In previous versions of React, you typically would pass an object to the setState method to update state. In this video, we look at how to use a callback function to update component state.
- [Narrator] One of the ways that we can change data…in our application is to use set state.…We're gonna take a look at how set state…has functioned for awhile…and then we're also going to look at how we can pass…instead of an object, a function, to set state.…So the first place I wanna start here…is let's get rid of our previous data…in our previous component…we also are going to be rendering a menu component instead.…Now the menu component is going to be responsible…for rendering a menu, so we'll make this a class component.…
And this should have, of course, a render method,…we're also going to set up some initial state…so I'll add the constructor.…Now the constructor always takes in props.…And we can call super with those props as well.…The next step is I want to initialize our state…so we'll say this dot state…will give meal a value of spaghetti…and then within our render…we're going to return the following.…
Now what we should return is, at this point, just the div.…Let's add another component here on line 11.…
- 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.