Tell us what’s happening:
Why this does not pass the one test which is Redux store should initialize with state of 0. Bug ?
Your code so far
const INCREMENT = 'INCREMENT'; // define a constant for increment action types
const DECREMENT = 'DECREMENT'; // define a constant for decrement action types
const initState = 0;
const counterReducer = (state = initState, action) => {
switch (action.type) {
case INCREMENT: return state + 1;
case DECREMENT: return state - 1;
case "RESET": return 0;
default: return state;
}
}; // define the counter reducer which will increment or decrement the state based on the action it receives
const incAction = () => ({
type: INCREMENT
}); // define an action creator for incrementing
const decAction = () => ({
type: DECREMENT
}); // define an action creator for decrementing
const store = Redux.createStore(counterReducer); // define the Redux store here, passing in your reducers
store.dispatch({type: "RESET"});
console.log(store.getState());
store.dispatch(incAction());
store.dispatch(incAction());
store.dispatch(decAction());
store.dispatch(decAction());
store.dispatch(decAction()); //-1
console.log(store.getState());
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.62 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/front-end-libraries/redux/write-a-counter-with-redux/