Answer the question
In order to leave comments, you need to log in
Why is it possible to write id without a dot in the function parameter?
Good afternoon, dear experts, please tell me: Here is a function
deleteTask= task => {
this.setState({
tasks: this.state.tasks.filter((item) => {
return item.id !== task.id;
})
})
}
deleteTask= taskId => {
this.setState({
tasks: this.state.tasks.filter((item) => {
return item.id !== taskId;
})
})
}
Answer the question
In order to leave comments, you need to log in
You are passed the task id to the deleteTask function when deleting, not the task object. TaskId is just the name of the function parameter.
Probably, when you say that there is an ID in the task, look in another scope - in fact, at the time the function is running, a number is still passed (at the place where the function was called), and because you renamed the parameter to task, the object did not come there, but the number is still coming
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question