Implement a Higher Order Component

InstructorKent C. Dodds

Share this video with your friends

Send Tweet

Sometimes you have some boilerplate for components that would be nice to abstract away slightly with a simple helper function. In this lesson we'll learn how to create a "Higher Order Component" which is a component factory function. We'll use it to give a given component a prop for our context value.

Raquel
~ 6 years ago

Anyone has tried this with Typescript? It's quite hard to define/type the props and the result component :/

Kent C. Doddsinstructor
~ 6 years ago

Tomeu, this is actually one of the reasons that higher order components have fallen out of favor in the community. Generally prefer a render prop over a higher order component :)