https://www.freecodecamp.org/learn/front-end-libraries/redux/register-a-store-listener

Tell us what’s happening:

  **Your code so far**

const ADD = 'ADD';

const reducer = (state = 0, action) => {
switch(action.type) {
  case ADD:
    store.subscribe(callBack);
    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});
console.log(count);
store.dispatch({type: ADD});
console.log(count);
store.dispatch({type: ADD});
console.log(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:

Okay, you’ve written your callback function:

const callback = () => {
  count++;
}

But you still have to subscribe it to the store. To do it you can use store.subscribe().

For example the code below would log “Hello” to the console every time an action is dispatched against the store:

store.subscribe(() => {
  console.log("Hello");
}