Reputation: 259
Is there a way to pass argument to setState(function(prevState, props, custom_rgument)?
removeTodo(evt) {
this.setState((prevState, props, evt) => ({
todoList: [...prevState.todoList.slice(0, evt), ...prevState.todoList.slice(evt + 1)]
}))
}
Or the only way to achieve this is to work with state?
removeTodo() {
this.setState(prevState => ({
todoList: [...prevState.todoList.slice(0, this.state.index), ...prevState.todoList.slice(this.state.index + 1)]
}))
}
Upvotes: 0
Views: 1071
Reputation: 18546
There shouldn't be a need to pass the evt
parameter to the setState
function. It's available in the scope anyways.
removeTodo(evt) {
this.setState(prevState => ({
todoList: [
...prevState.todoList.slice(0, evt),
...prevState.todoList.slice(evt + 1)
]
}));
}
Upvotes: 1