0

What exactly is the difference between

onclick="myFunction()"

and

In normal JS - document.getElementById("demo").addEventListener("click", myFunction);

In React - onClick={onClickFunction}>

In the first one, we are calling the function. But in the second one, we are passing the function as a reference.

So when we pass the function reference, how does the function gets called when the click event happens?

Both works exactly as expected. But I would like to understand the underlying concept.

Albina
  • 1,901
  • 3
  • 7
  • 19
  • Does this answer your question: [addeventlistener-vs-onclick](https://stackoverflow.com/questions/6348494/addeventlistener-vs-onclick) ? – kca Mar 12 '23 at 09:04
  • In React it is something special, see [React SyntheticEvent](https://reactjs.org/docs/events.html). – kca Mar 12 '23 at 09:22

0 Answers0