In this video, we look at how to change state using setState with the context API. This will make data accessible at any level of the component tree.
- [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 responsible…for taking the status and changing it to closed.…So, our button will be called Close Resort,…
- 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.