Current section: Advanced State Management 36 exercises
solution

Previous State

Loading solution

Transcript

00:00 First things first, I'm going to change this setCount to, whoops, right there, to changeCount. And now we're going to change it by the step. So this will be plus the step, this will be minus the step. That is the API that we're looking to create.

00:17 And so to make that API work, this state is going to be the current count. We'll just call it the count. And now we know for sure it's a number. And this action, the second argument here, this is now going to be the change, the amount that our count is going to change.

00:35 So the new count is going to simply be the count plus the change, whatever that change is. And that allows us to have this new API, which allows us to say changeCount. And there we go. We increment and decrement. We can change the step. And now we're incrementing by fours,

00:53 all because we changed the implementation of our reducer. We were able to change the name of this to be something that actually describes what is going to happen when you call that function. There you go.