Dan Abramov recommends that developers separate stateful and stateless components to maintain a separation of concerns. He suggests that we create top-level container components that contain many presentational components. The container components manage the application’s state and pass it to the presentational component to render it.

Let’s start by looking at how props are passed from a Parent to a Child component in React.

Basic prop drilling

In this example, <Mother /> is the container component that holds the application’s state. <Mother /> passes the lastName as a prop to <Child /> . <Child /> then displays the lastName .

This pattern gets much more complicated when the application grows in size and complexity.

More complex prop drilling

In the above example, the Grandmother component manages the application’s state. It holds the lastName attribute on its state. The Child component displays the lastName. In this case, the Child only knows about the lastName because the prop has been passed down (drilled) through the component tree from Grandmother to Mother to Child . It’s like a game of telephone.

The major benefit of prop drilling is that even as state changes, it updates all of its children with that new state.

For example, what if the Grandmother immigrated to the United States, and the immigration officers changed her last name to Smith, from Sanchez.

Prop Drilling with a State Change

As your application continues to grow, you may notice that you start changing the names of your props as you pass them down in the hierarchy. It will become harder to determine where data is coming from, and debugging will become more difficult. You’ll also find that you’re passing data through components that have no reason to know about that information!

When you can’t easily determine the origin of your data, you should consider introducing an alternative state management solution to your application. If you’re using React 15, you can implement something like redux or MobX. In React 16, you can also consider using Context.

🌟 If you liked this post, make sure to follow me on medium, follow me on twitter, and support me on Patreon!🌟