What is a HOC?

Definition

A Higher Order Component is a function that takes a component and returns a new component with extra behaviour. Same idea as higher-order functions (map, filter) but for components.

const EnhancedComponent = withSomething(OriginalComponent);
  • Reuse logic: loading spinners, auth checks, logging, permissions.
  • Naming convention: withXyz.
  • The HOC must pass through all props: <Wrapped {...props} />.