Working with React/Redux to do some CRUD operations, and I need to update an object that is housed in an array in my state. How would I go about doing that?
My state looks like this:
var state = {
insiders: [{object},{object}]
}
and My action object looks like this:
action = {
type: 'UPDATE_INSIDER',
payload: {
insider: _insider
}
}
I was originally thinking the reducer case would look like this, but I'm not sure. (only been working with react/redux since last week)
case UPDATE_INSIDER:
let insiders = state.insiders;
insiders = insiders.filter(x => x.firstName !== payload.insider.firstName);
return{ ...state, insiders: insiders.concat(payload.insider) }
- Does this work?
- Can it work better?