I understand that this is not the right way to make a button show an alert on click.
I would like to understart the logic behind this. I understand that on click needs to get a reference to a function in order to function as expected.
In the following example, a reference is being made to an arrow function which will be called on click:
<button onClick={() => alert('hi)}>Click me!</button>
But what happens behind the scenes in this case:
<button onClick={alert('hi)}>Click me!</button>
Why is the statement inside onClick being evaluated at render?
Edit: I am using React.