...

/

Creating Higher-Order Component

Creating Higher-Order Component

Learn to refactor our code from the previous chapter to make a higher-order component in this lesson.

We'll cover the following...

Creating reusable higher-order component

At the bottom of this lesson, we have the test-driven-carousel project from the previous chapter, take a look at the Carousel component. In addition to rendering a somewhat complex DOM tree, it also has one piece of state and two event handlers that manipulate that state. Let’s try building an HOC that encapsulates that logic.

  • Well-implemented HOCs tend to be highly reusable, and this one will be no exception. It’ll manage the state for any component with an “index” prop, meaning a number that can go from 0 up to some limit. Call it HasIndex. Start with a ...