-2

onRemove(id) is a function which filtering id that gets from parameter.

case 1)

const namesList = names.map(name => (<li key={name.id} onDoubleClick={onRemove(name.id)}>
{name.text}</li>));

case 2)

const namesList = names.map(name => (<li key={name.id} onDoubleClick={()=> onRemove(name.id)}>
{name.text}</li>));

I don't know the difference between case 1 and case 2.

김상록
  • 11
  • 1
  • Then use a better code editor and format the code: the function inside the `map` in the first case returns something _completely different_ from the second case. – Mike 'Pomax' Kamermans Jan 03 '21 at 01:36

1 Answers1

0

In the first case you are passing parameter id without using binding and in the second case you are using arrow function to pass the parameter which is equvalent to binding.

Expected behaviour

case 1 onRemove(id) function will be call immediately after component render (in example you will see console log on each refresh)

case 2 onRemove(id) function will be call when you make double click(in example you will see console log on double click)

To know more about passing parameter and how to bind a function follow this,this

Example

mirsahib
  • 375
  • 1
  • 4
  • 12