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

const store = Redux.createStore(reducer);

// Global count variable:
let count = 0;
//const addOne = () => (count += 1);
// Change code below this line
const addOne = () => (count += 1);

store.subscribe({type: ADD});
console.log(count);
// 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/103.0.0.0 Safari/537.36

Challenge: Redux - Register a Store Listener

Link to the challenge:

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 are passing an object to store.subscribe() not a callback function.

store.subscribe(someCallbackFn);

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