title: Updating the array object in React state using immutability helper
body: <p>I am updating an object within an array in React state using <a href="https://facebook.github.io/react/docs/update.html" rel="noreferrer">immutability helper</a>.</p>
  
  <p>The object I want to modify is nested: </p>
  
  <pre class="lang-js prettyprint-override"><code>this.state = {
    a: {
      b: [{ c: '', d: ''}, ...]
    }
  } 
  </code></pre>
  
  <p>I want to update the prop c within the nth element of b using immutability helper.</p>
  
  <p>The equivalent code without the immutability helper is:</p>
  
  <pre class="lang-js prettyprint-override"><code>const newState = Object.assign({}, this.state);
  newState.a = Object.assign({}, newState.a);
  newState.a.b = newState.a.b.slice();
  newState.a.b[n] = Object.assign({}, newState.a.b[n]);
  newState.a.b[n].c = 'new value';
  this.setState({ newState });
  </code></pre>
  
  <p>I know the above code is a bit ugly. I am assuming the code using immutability helper will solve my problem. Thanks</p>