Answer the question
In order to leave comments, you need to log in
How to push to a state property?
I wrote a form that sends its content to the global state. The reducer looks like this:
const messagesReducer = function messagesReducer(state = { messages: [] }, action) {
switch(action.type) {
case 'SET_MESSAGE': {
// state = {
// ...state,
// messages: state.messages.push(action.payload),
// };
state.messages.push(action.payload);
break;
}
default:
return state;
}
return state;
}
Uncaught TypeError: state.messages.push is not a function
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question