Register a Store Listener HELP PLEASE

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

  **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 store.subscribe = () => (count += 1);
// 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 (Windows NT 10.0; Win64; x64; rv:92.0) Gecko/20100101 Firefox/92.0

Challenge: Register a Store Listener

Link to the challenge:

You are trying to define store.subscribe. This method already exists – you just have to call it, passing in a function. The function you pass to store.subscribe will get called every time you dispatch an action.

Thank you very much !

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