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.
Understanding the context API - React.js Tutorial
From the course: React: Components, Context, and Accessibility
Understanding the context API
- [Instructor] In React applications we create nested component trees to compose our user interfaces. In early React apps sometimes you'd see state everywhere. This made it really easy to get some data quickly, but having state all over your app made it difficult to keep those values in sync. The common ideology then became, hey, instead of putting state everywhere, let's only put it at the root. Then we can pass down state data to components via props. So this starts out fairly straightforward. We can create a parent component that renders a child component. Let's go ahead and do this. So here on line 11 I'm going to create a component called resort. This is gonna have some state, which is just the name of the resort. And then we're gonna render something. So let's render a div that just displays that name. All right and then we're going to go ahead and render this resort. Perfect. Next up let's create that child…
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)
-
-
-