in React JS by
Q:

What is the recommended approach of removing an array element in React state?

1 Answer

0 votes
by

he better approach is to use Array.prototype.filter() method.

For example, let's create a removeItem() method for updating the state.

removeItem(index) {
  this.setState({
    data: this.state.data.filter((item, i) => i !== index)
  })
}
Click here to read more about React JS
Click here to read more about Insurance

Related questions

+1 vote
asked Jul 16, 2019 in JavaScript by Indian
0 votes
asked Dec 8, 2020 in React JS by SakshiSharma
0 votes
0 votes
asked Nov 6, 2019 in Agile by sachatouille
+1 vote
asked Jan 20 in C Plus Plus by SakshiSharma
0 votes
asked Mar 13, 2020 in Agile by yourell
...