title: React Native set state an element of array of objects
body: <p>I have an array in my state:</p>
  
  <pre><code>this.state = {
    data: [
      {
        quantity: 0
      }
    ],
    tempQuantity: 0
  };
  </code></pre>
  
  <p>I want to update my <code>data[0].quantity</code> in a <code>TextInput</code> so i use:</p>
  
  <pre><code>onChangeText={tempQuantity =&gt;
    this.setState({
      tempQuantity,
      data: [...this.state.data, { quantity: tempQuantity }]
    })
  }
  </code></pre>
  
  <p>And i have a <code>&lt;Text&gt;</code> to show the result:</p>
  
  <pre><code>&lt;View&gt;
    &lt;Text&gt;{this.state.data[0].quantity}&lt;/Text&gt;
  &lt;/View&gt;
  </code></pre>
  
  <p>But I get <code>0</code> every time!</p>
  
  <ol>
  <li><p>How can I update each element of each object in an array?</p></li>
  <li><p>If I use it this way, it will work dynamically? I mean i want to create an object (with all properties of the main object) every time I press a <code>&lt;Button&gt;</code>. [ for example: <code>data[0]</code> with <code>quantity</code> of 10 - <code>data[1] with</code>quantity` of 12 - and ...  ]</p></li>
  </ol>