Tell us what’s happening:
I m getting the following errors, basically saying the program isn’t working as expected
" The Redux store should initialize with a state
of 0.
Dispatching incAction
on the Redux store should increment the state
by 1.
Dispatching decAction
on the Redux store should decrement the state
by 1.
"
But i tested it using the console.log statements at the end of the code, and it shows the state has been initialized to 0, incrementing and decrementing correctly.
0
2
1
I m lost at what the lessons is expecting.
Your code so far
const INCREMENT = 'AT_INCREMENT'; // define a constant for increment action types
const DECREMENT = 'AT_DECREMENT'; // define a constant for decrement action types
const counterReducer = (state={ count:0 }, action) => {
let result = state.count;
switch(action.type) {
case INCREMENT:
result++;
return {
type:INCREMENT,
count:result
};
case DECREMENT:
result--;
return {
type:DECREMENT,
count:result
};
default:
return state;
}
};
// define the counter reducer which will increment or decrement the state based on the action it receives
const incAction = ()=>{
return {
type:INCREMENT
};
}; // define an action creator for incrementing
const decAction = () => {
return {
type:DECREMENT
};
}; // define an action creator for decrementing
const store = Redux.createStore( counterReducer );
// define the Redux store here, passing in your reducers
console.log(store.getState().count);
store.dispatch(incAction());
store.dispatch(incAction());
console.log(store.getState().count);
store.dispatch(decAction());
console.log(store.getState().count);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:65.0) Gecko/20100101 Firefox/65.0
.
Link to the challenge: