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.
Referencing context in stateless functional components - React.js Tutorial
From the course: React: Components, Context, and Accessibility
Referencing context in stateless functional components
- [Narrator] In the last lesson, we looked at how the provider can pass data to a child component that uses the consumer. In this video, we'll take a look at how to change state using the context API. The first place I want to start is I want to add another state variable. So, we're gonna set up a value called status, which we'll set to OPEN. So this will mean the resort is open, closed, or perhaps on hold. The next step is I want to adjust the trail component a little bit. So, right now, we are rendering our consumer, and then we render this one paragraph tag, let's actually render a little bit more here. So, let's render a div, and this div is going to wrap around this paragraph. Now, we're displaying the context here, let's also display the status, so we'll say the resort is context.state.status, and then finally, we want to add a button. So, here's where things get interesting. The button is going to be…
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)
-
-
-