React · Junior · Question 58 of 75
How do you pass an argument to a click handler?
{todos.map((t) => <button key={t.id} onClick={() => remove(t.id)}>×</button>)}- ✓Correct answer: Wrap the call in an arrow function:
onClick={() => remove(t.id)} - 2
onClick={remove(t.id)} - 3
onClick={remove, t.id}
Explanation
onClick expects a function. remove(t.id) would run during render and pass its return value as the handler.