You’ve added some complexity to this. But first let’s talk about what you have here:
const defaultState= {
counter: 0
}
If your state is like that, then the innards of your reducer should look something like:
switch (action.type) {
case INCREMENT:
return {counter: state.counter + 1}
break;
case DECREMENT:
return {counter: state.counter - 1}
break;
default:
return state
}
But…
That isn’t what your state should look like. You’ve made the state an object and created a property called counter. Now, that is a very reasonable and even sensible thing to do. But it is not what they’ve asked for here. The challenge isn’t very specific, but they just want the simplest state possible. They just want a number. So, your default state should just be:
const defaultState = 0;
So, the reducer state is your counter. Yes, often you would create an object like you did. But they are trying to keep this simple. With this in mind, can you see how you need to adjust your reducer to make this work? Understanding that the state itself is the counter?
Funny you said that…because I actually started out with something similar to what you said except that instead of const defaultState = 0; I set const counter= 0; (see code - part 2). I deleted that after seeing what others had done. Since that did not work either, I tried your way (const defaultState = 0;, see code - part 1). But am still getting the same errors…??
You want to return the new state. Your old state is the variable state. Basically, return what you want the new state to be. Not wrapped in an object - remember that state is not an object in this case, just a number. So, take it out of the object, and don’t add 1 to the defaultState add it to the …