Redux - Register a Store Listener

Tell us what’s happening:
Describe your issue in detail here.

Your code so far

const ADD = 'ADD';

const reducer = (state = 0, action) => {
  switch(action.type) {
    case ADD:
      return state + 1;
      return state;

const store = Redux.createStore(reducer);

// Global count variable:
let count = 0;

// Change code below this line
const addOne = () => (count += 1);
function sayHi() {
// Change code above this line

store.dispatch({type: ADD});
store.dispatch({type: ADD});
store.dispatch({type: ADD});

Your browser information:

User Agent is: Mozilla/5.0 (iPhone; CPU iPhone OS 16_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.0 Mobile/15E148 Safari/604.1

Challenge: Redux - Register a Store Listener

Link to the challenge: don’t know what’s wrong with my code

Why are you passing sayHi to subscribe?

The callback to store.subscribe should also increment the global count variable as the store is updated.

I just updated the hint page with two solutions as I have seen this happen before. I only added the solution part and not the full code, but I can edit it again if that is really needed.

I know, but you would think the code comments should make it clear what part of the code it is for.

Also, if people really blindly copy and paste that and replace everything else I wonder how they ever managed to get to this part of the curriculum. Maybe catching such blind copy-pasting would really be for the best as it would point to some serious lack of understanding.

But I updated the solutions to be the complete code.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.