From the course: React: Components, Context, and Accessibility

Unlock the full course today

Join today to access over 22,700 courses taught by industry experts or purchase this course individually.

setState() changes

setState() changes - React.js Tutorial

From the course: React: Components, Context, and Accessibility

Start my 1-month free trial

setState() changes

- [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…

Contents