React · Middle · Question 18 of 75
What is a higher-order component (HOC)?
- ✓Correct answer: A function that takes a component and returns a new one
- 2A component located at the very top level of the tree
- 3A component with more than a certain number of descendants
Explanation
Example: withAuth(Page) checks authentication and renders Page or a redirect. HOCs were popular before hooks. Downsides: "wrapper hell", prop name collisions, complex typing. Today such logic is usually moved into custom hooks.