0 votes
in ReactJS by

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)
  })
}

Related questions

0 votes
0 votes
asked Nov 1, 2023 in ReactJS by AdilsonLima
0 votes
0 votes
asked Oct 28, 2023 in ReactJS by DavidAnderson
...