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