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

Tell us what’s happening:

  **Your code so far**

const ADD = 'ADD';

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

const store = Redux.createStore(reducer);

// Global count variable:
let count = 0;

// Change code below this line
const callBack=()=>(count+=1);
// Change code above this line

store.dispatch({type: ADD});
store.subscribe(callBack);
console.log("one" + count);
store.dispatch({type: ADD});
store.subscribe(callBack);
console.log("two" + count);
store.dispatch({type: ADD});
store.subscribe(callBack);
console.log("three" + count);

  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36.

Challenge: Register a Store Listener

Link to the challenge:

I have answered already to your first topic here:

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