What is a React higher-order component (HOC)?
A function that takes a component and returns a new component with added behavior. It is a higher-order function for components. Example: withAuth(Component) returns a component that redirects to login if not authenticated.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in Real-World Higher-Order Functions in JavaScript
Event handlers, middleware (Express, Redux), React higher-order components, debounced search, memoized API calls, configurable validators, and array pipelines. HOFs are everywhere in modern JavaScript.
Middleware is a function that takes a store and returns a function that takes next and returns a function that takes action. Each layer is a HOF that adds behavior. Express and Redux middleware work this way.
debounce is a HOF that takes a function and a delay, and returns a new function that delays the call until activity stops. The returned function closes over a timer (closure). It is used for search inputs, resize handlers, etc.
Still have questions?
Browse all our FAQs or reach out to our support team
