The context API uses the provider to pass data to other components in the tree. Then, we use the consumer to receive and display the data in child components.
- [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 props children.…We're gonna use state is this.state.…
- What's new in React 16
- Rendering arrays
- Controlled, uncontrolled, and compound components
- Using keyed fragments
- Working with new lifecycle methods
- React patterns
- Using the context API
- Checking for accessibility issues in your React code
Skill Level Advanced
1. What’s New in React
2. Advanced Components
3. Enhanced Components
4. React Patterns
5. React Accessibility
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.