From the course: React Hooks

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Placing data in context

Placing data in context - React.js Tutorial

From the course: React Hooks

Start my 1-month free trial

Placing data in context

- [Instructor] There are times when we want values to be available to the entire component tree. Instead of passing data up and down the tree, we can put the data in context so that all of the child components will know the values that are being passed down. So if you've worked with context in React before, this is kind of the new way to do it using React hooks. So let's go ahead and create a component that's going to consume some data from context. This is going to involve getting rid of our use input stuff. That served us well but we're ready to move on. And we also want to import createContext from react. Now, createContext is what we're going to use here. We're going to say export const TreesContext, so we're going to create this context. It's just like this little container where we're going to be able to store some data that can be consumed by any of the components that are part of the component tree. The data that we…

Contents