Loading…
A short voice session: one question, one follow-up, then instant feedback — up to 5 minutes.
The first passes the function so React calls it on click; the second calls it during render. To pass an argument, wrap it: onClick={() => handleClick(id)}.
React expects a function for an event prop. onClick={handleClick} hands over the function, and React calls it with the event when the user clicks. onClick={handleClick()} runs handleClick immediately during render and passes its return value, which is usually undefined; if the handler sets state, this can even cause an infinite re-render loop. To pass extra data, create a small arrow function, such as onClick={() => remove(item.id)}, or read a data attribute from the event.