Question · JavaScript and React course · Module 3: State and Events

onClick Event Handler

How do you correctly handle a button click in React?

Answer options

  • <button onClick={handleClick()}>Click</button> - we invoke the function in the attribute
  • <button onClick={handleClick}>Click</button> - we pass a reference to the function
  • <button onclick='handleClick()'>Click</button> - we use the HTML attribute
  • <button click={handleClick}>Click</button> - we omit the 'on' prefix

You can check the correct answer by solving this task in the CodeWorlds game.