From the course: React: Components, Context, and Accessibility
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Using context - React.js Tutorial
From the course: React: Components, Context, and Accessibility
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
(Locked)
Understanding the context API3m 45s
-
(Locked)
Using context3m 45s
-
(Locked)
Referencing context in stateless functional components2m 34s
-
(Locked)
Working with higher-order components7m 31s
-
(Locked)
Working with render props3m 54s
-
(Locked)
Render props in the wild: React Apollo46s
-
(Locked)
Solution: Building a context-based theme system2m 24s
-
(Locked)
-
-
-