Higher-Order Components (HOCs)
Learn how higher-order components wrap a component to inject additional props or behavior, and why hooks replaced most use cases.
A higher-order component (HOC) is a function that takes a component and returns a new component with additional props or behavior layered on top — conventionally named withSomething(Component). This mirrors higher-order functions in general JavaScript, applied specifically to the problem of sharing cross-cutting concerns (like injecting a theme, auth state, or data-fetching results) across many components.
An HOC is like a gift-wrapping service that takes your product (component) and wraps it in successive layers of packaging (each HOC), where each layer can add its own extra insert (injected props) — useful, but stacking many layers makes it harder to see the original product without unwrapping each one.