Reputation: 1735
When I update the redux state it gives error TypeError: object is not iterable (cannot read property Symbol(Symbol.iterator))
const initialState = {
articles: []
};
function rootReducer(state = initialState, action) {
switch(action.type){
case ADD_ARTICLE:{return [...state,action.payload];} # error occurs in this line
default:return state;
}
}
export default rootReducer;
Upvotes: 2
Views: 140
Reputation: 15166
You are trying to clone the state which is {}
and not []
. Try to return as the following:
switch(action.type) {
case ADD_ARTICLE: {
return {
...state,
action.payload
};
}
default: {
return ...state;
}
}
Upvotes: 3