0

I try to send to my Redux state an array of objects and I try to save it in my state.

Redux State:

savedEvents: [],

My array of elements I try to send looks like: [{1},{2}]

My dispatch method :

case 'events/setNewEvent': 
            return { ...state, savedEvents: [...state.savedEvents, action.payload] }; 

If I try to use this 'case', my 'savedEvents' will look like [[{1},{2}]] ant not like [{1},{2}]. Both will be on index 0.

What I have to change in my code to be saved individually, and not together?

0

1 Answer 1

0

You just have to spread the new events in with the ... operator:

return { ...state, savedEvents: [...state.savedEvents, ...action.payload] }; 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.