React TutorialLesson 44Free preview
React HOC
This lesson is part of React · All levels
Summary
A Higher-Order Component is a function that accepts one component and then returns a new component with additional behavior, similar to the higher-order pattern function in JavaScript. HOC is suitable for cross-component logic such as authentication, logging, or theme carrying. The original components were not altered, only wrapped by the HOC resulting components.
Key points
- HOCs are shaped
- HOC doesn't change the original component, just wrap it up.
- Props are passed to the original component with the spread operator
- Famous examples: connect on Redux and withRouter
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.