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 this.state variable directly, is
this.state
Here is a way to remove the element from the array in the state using ES6 spread syntax.
onRemovePerson: (index) => { const data = this.state.data; this.setState({ data: [...data.slice(0,index), ...data.slice(index+1)] }); }