From the course: React: Components, Context, and Accessibility

Unlock the full course today

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

Using context

Using context - React.js Tutorial

From the course: React: Components, Context, and Accessibility

Start my 1-month free trial

Using context

- [Instructor] Let's take a closer look at how we can use context to pass data down to our child components. The first step is we're going to create a context value, which will be called Context, and this is going to use a function called createContext from the react package. Next, we're gonna create a provider. So, the provider is gonna be responsible for passing data down to the children. So class Provider extends React.Component. Now, instead of using state in the resort component, we're gonna move this. Let's just cut and paste this into the provider, and this will set up our initial state that can be passed down. Next, we wanna render something. What we'll render in this case is the context provider. This is a tag Context.Provider that will wrap around this.props.children. So, Context.Provider and then any children will be displayed right here. Okay. Now the thing I'm missing here on line 19 is I need to pass in a value. So this value is going to be what we pass down to these…

Contents