title: Removing element from array in component state
body: <p>I am trying to find the best way to remove an element from an array in the state of a component.  Since I should not modify the <code>this.state</code> variable directly, is there a better way (more concise) to remove an element from an array than what I have here?:</p>
  
  <pre><code>  onRemovePerson: function(index) {
      this.setState(prevState =&gt; { // pass callback in setState to avoid race condition
        let newData = prevState.data.slice() //copy array from prevState
        newData.splice(index, 1) // remove element
        return {data: newData} // update state
      })
    },
  </code></pre>
  
  <p>Thank you.</p>
  
  <p><strong>updated</strong></p>
  
  <p>This has been updated to use the callback in setState. This should be done when referencing the current state while updating it.</p>