Tell us what’s happening:
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);
let carIsBroken = true;
const callCarOwner = () => console.log("Hello your car is done!");
const fixCar = (carIsBroken, callCarOwner) => {
if (carIsBroken === true) {
carIsBroken = false;
}
console.log(carIsBroken);
// After the car is fixed, the last thing we do is call the car owner - that's our 'callback function'.
callCarOwner();
};
fixCar(carIsBroken, callCarOwner);
let count = 1;
const addOne = () => (count += 1);
function sayHi(addOne) {
return count;
}
store.subscribe(sayHi);
// 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/84.0.4147.89 Safari/537.36
.
Challenge: Register a Store Listener
Link to the challenge: