React · Junior · Question 18 of 75

What's wrong with <button 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.

Further reading

Problem with a question

React · Junior · question 18

Test yourself

Take the React · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz