Clarkie Clarkie - 1 year ago 117
React JSX Question

Updating nested data in redux store

What's the best/correct way to update a nested array of data in a store using redux?

My store looks like this:

1: {
id: 1,
key: "value",
links: [
id: 10001
data: "some more stuff"

I have a pair of asynchronous actions that updates the complete
object but I have another pair of actions that I want to update a specific

My reducer currently looks like this but I'm not sure if this is the correct approach:

switch (action.type) {
// TODO: check whether the following is acceptable or should we create a new one?
return Object.assign({}, state, {
items: state.items,

Answer Source

React's update() immutability helper is a convenient way to create an updated version of a plain old JavaScript object without mutating it.

You give it the source object to be updated and an object describing paths to the pieces which need to be updated and changes that need to be made.

e.g., if an action had id and link properties and you wanted to push the link to an array of links in an item keyed with the id:

var update = require('react/lib/update')

// ...

return update(state, {
  items: {
    []: {
      links: {$push:}

(Example uses an ES6 computed property name for

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download