A
A
AlexFo902019-03-08 09:25:57
JavaScript
AlexFo90, 2019-03-08 09:25:57

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

it doesn’t work like this, although there is an id in the task, and it comes checked, but does not delete, and the function below works as it should, but taskId without a dot is passed in the parameter !!!! I can’t google why it works like this, does React itself put an end to it? And why might the first solution not work? what is the difference between them? Thanks in advance!
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

1 answer(s)
D
Decadal, 2019-03-08
@AlexFo90

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 question

Ask a Question

731 491 924 answers to any question