How to 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;
  default:
    return state;
}
};

const store = Redux.createStore(reducer);

// Global count variable:
let count = 0;

// Change code below this line

// 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 (Linux; Android 10; TECNO KB8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.99 Mobile Safari/537.36

Challenge: Register a Store Listener

Link to the challenge:

It would be very helpful if you described what problem you are having.

Also, we don’t want to just give you and answer, so please try something so we can give you feedback.

The instructions say:

Write a callback function that increments the global variable count every time the store receives an action, and pass this function in to the store.subscribe() method. You’ll see that store.dispatch() is called three times in a row, each time directly passing in an action object. Watch the console output between the action dispatches to see the updates take place.

So, you need to add that method in and give it a callback function that will increment the count. You should do it here:

// Change code below this line

// Change code above this line

As a hint, this is a one line solution. You just need to call that method with a very simple callback function.

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