Pass down props using React childContextTypes in a deeply nested component tree

In our previous article on React childContextTypes we saw how React lets you accumulate props along a nested hierarchy. At the time of writing, I wasn’t aware that there is one more characteristic of childContextTypes that is extremely handy

Properties specified in childContextTypes are propagated along the the hierarchy even if none of the intermediate components in the hierarchy implement either the getChildContext method or have the childContextTypes property.

See the below example for some more clarity and fork THIS JSFIDDLE to experiment with it yourself.

Ryan Sukale

Ryan is just a regular guy next door trying to manage his life and finances.

2 Responses

  1. Dan says:

    This isn’t working 🙁

  1. November 8, 2016

    […] and it might change in future versions of React. (Good tutorials on using Context are here  and here.) In my case, I use Context only for giving child components a callback for sending a message to […]

Leave a Reply

Your email address will not be published. Required fields are marked *