Composition with higher-order components
In this last section of the chapter, we'll cover higher-order components. If you're familiar with higher-order functions in functional programming, higher-order components work the same way. A higher-order function is a function that takes another function as input, and returns a new function as output. This returned function calls the original function in some way. The idea is to compose new behavior out of existing behavior.
With higher-order React components, you have a function that takes a component as input, and returns a new component as output. This is the preferred way to compose new behavior in React applications, and it seems that many of the popular React libraries are moving in this direction if they haven't already. There's simply more flexibility when composing functionality this way.
Conditional component rendering
One obvious use case for a higher-order component is conditional rendering. For example, depending on the outcome of some...