Tell us what’s happening:
I’m trying to clear the “The callback to store.subscribe
should also increment the global count
variable as the store is updated.” test. But I do not know what to do 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 = 1;
const addOne = () => (count += 1);
// Change code below this line
function sayHi() {
console.log("Hi!");
}
store.subscribe((sayHi) => { ++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/106.0.0.0 Safari/537.36 Edg/106.0.1370.42
Challenge: Redux - Register a Store Listener
Link to the challenge: