I
I
Igor Shumilovsky2015-12-18 13:31:45
React
Igor Shumilovsky, 2015-12-18 13:31:45

How to add a new object inside an array in state in Redux?

There is an array of objects as a parameter of the User object. How to write a handler for adding an object in a reducer as shown in the diagram below? Please tell me
state
-- user:
----name: 'bla-bla'
----patients: ['how to add an object here?']
The state with the user object comes to the input of the reducer

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor Shumilovsky, 2015-12-18
@JiSeven

Is this the right way for redux? Or are there other options?

case types.ADD_NEW_PATIENT: 
   var patients = state.patients
   patients.push(action.patient)
   return {
     ...state,
     patients: patients
   }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question