Current section: Advanced State Management 36 exercises
Problem

State Object

Loading exercise

Transcript

00:00 So we're going to expand this even further and say, what if we had multiple state properties? Maybe it's not just a count, but it's a count and some other state. So we're going to change to an object of state rather than just a number. So our initial state is going to be this object that has a count property.

00:19 This will no longer be the count, we'll call it state and we'll call this set state. Then we can pluck the count off of the state with destructuring here. Then our increment and decrement functions will call set state providing the count change right here.

00:34 So we're going back to specifying what we want the state to be. But we're going to do a little bit more than that because we want to be able to make it so you can have some other state, but still not have to specify that other state. So I want to be able to say, let's increment, we'll call set state with,

00:54 here's the count property, but the resulting state should still have this some other state. So we've got to merge the old state with the changes that we're making. So that is your objective in this exercise. Let's get going.