React · Junior · Question 18 of 75
What's wrong with <button onClick={handleClick()}>?
- 1Nothing, it's the standard syntax
- ✓Correct answer: The function is called immediately during render, not on click
- 3In JSX, handlers are written as a string:
onClick="handleClick()"
Explanation
onClick needs a function, not the result of calling it. Correct: onClick={handleClick}, or onClick={() => handleClick(id)} if you need arguments. If handleClick changes state, calling it during render causes an infinite loop.