First of all, at this point in your learning, you should be a doing a better job describing your problems. This is an important skill for a developer. That and being able to search online for answers.
But yeah, redux is weird at first. Don’t get frustrated.
The instructions was:
Write a callback function that increments the global variable count every time the store receives an action…
I think that is a poorly worded sentence, It should tell you to write a function that increments the global variable count, which is defined a few lines above.
const incrementCount =()=>{ store.getState() +1}
That does nothing with the global variable count. It also really doesn’t do anything - it retrieves the state (which it doesn’t need to do) and then adds 1 to it, and then does nothing with that value - it disappears into the mist.
You just need a function that increments count.
Then…
… and pass this function in to the store.subscribe() method.
You are passing it a function that logs out something (which it doesn’t need to do). You are assuming that subscribe is going to pass in a parameter called “incrementCount” - note that this is not the function you created - you think subscribe is going to pass something in there, you just gave it the same name.
But you don’t have to worry about anything like that - just pass your callback function to subscribe - it’s simpler than what you’re trying.
Try it again. If it doesn’t work, show us what you’re trying and we’ll get you closer.
OK, I thought about it a little more. Yes, your callback function can just increment count itself. But I think the wording means that we want to use the store, like you did in your original callback. But we don’t need to do anything with it - it has already been incremented by the reducer - we just need to store it in our variable. Both approaches pass but I think the second is what they want.
It’s a confusing lesson and I’m not 100% sure why we’re doing this. But redux is confusing and is hard to teach, it’s hard to break into small chunks that make sense on their own.