I am getting the [Error: Objects are not valid as a React child (found: object with keys {counter, num}). If you meant to render a collection of children, use an array instead.] error for the below code :
const initialState = {
counter: 0,
num : 0
}
const counterReducer = (state = initialState, action) => {
switch(action.type){
case "INCREMENT":
{
return {
...state,
counter: state.counter + action.payLoad
}
}
case "DECREMENT":
return {
...state,
counter: state.counter - action.payLoad
}
default:
{
return state;
}
}
}
export default counterReducer;
If I do like below everything working fine:
const counterReducer = (state = 0, action) => {
switch(action.type){
case "INCREMENT":
return state + action.payLoad;
case "DECREMENT":
return state - action.payLoad;
default:
{
return state;
}
}
}
export default counterReducer;
question from:https://stackoverflow.com/questions/65918429/react-error-saying-objects-are-not-valid-as-react-child