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
The cleanest way to do this that I've seen is with filter:
filter
removeItem(index) { this.setState({ data: this.state.data.filter((_, i) => i !== index) }); }