React Core & Hooks (407 Qs)•Part 9: React Hooks Deep Dive (262 - 316)
What is the recommended approach of removing an array element in React state?
junior LevelCode ExampleHooksData Structures
The better approach is to use Array.prototype.filter() method.
rust
For example, let's create a `removeItem()` method for updating the state.
javascript
removeItem(index) {
this.setState({
data: this.state.data.filter((item, i) => i !== index)
})
}