09 / 10

Higher-Order Component (HOC) Pattern

A Higher-Order Component (HOC) is a function that takes a component and returns a new component, enabling code reuse, cross-cutting concerns, and component composition.

The Higher-Order Component pattern is a powerful technique in React for reusing component logic. An HOC is a function that accepts a component as an argument and returns an enhanced version of that component with additional props or behavior. This pattern is ideal for cross-cutting concerns like authentication, logging, data fetching, and styling. While React Hooks have replaced some HOC use cases, HOCs remain valuable for class components and specific composition scenarios.

Vanilla JavaScript Implementation (Function Composition)
React Implementation
Angular Implementation