Higher-Order Components (HOCs) in React

From the React Components & JSX cheat sheet ยท Component Patterns & Types ยท verified Jul 2026

Higher-Order Components (HOCs)

Functions that take a component and return an enhanced component

jsx
function withLogger(Component) {
  return function Wrapped(props) {
    console.log('Rendering', Component.name, props);
    return <Component {...props} />;
  };
}

const LoggedButton = withLogger(Button);
๐Ÿ’ก HOCs are functions that wrap a component to add behavior โ€” common in legacy code
โšก Modern React prefers custom hooks over HOCs for sharing logic
๐Ÿ“Œ Always spread {...props} to forward unrelated props to the wrapped component
๐ŸŸข HOCs are still useful for cross-cutting concerns like auth guards and analytics
hocpatterncomposition

More React tasks

Back to the full React Components & JSX cheat sheet