Tell us what’s happening:
I’m going through the redux section of the front end libraries certification and I am so confused at what it wants me to do here to make count go up when the store is updated. It says to make a callback function but the example they give requires a static variable whereas this problem deals with a function being called / a value changing so it gave me 0 clarification. I can think of how to do it in react but im completely lost with what to put within my function which I’ve aptly titled “idk”.
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
let idk = function(){
}
store.subscribe(idk)
// 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/83.0.4103.106 Safari/537.36
.
Challenge: Register a Store Listener
Link to the challenge: