Reputation: 19
I was learning about React in Codecademy when I came across this example:
class MyClass extends React.Component {
myFunc() {
alert('Stop it. Stop hovering.');
}
render() {
return (
<div onHover={this.myFunc}>
</div>
);
}
I noticed that when myFunc is called, no parentheses were used and was wondering why. I would appreciate it if someone could explain it.
Upvotes: 0
Views: 666
Reputation: 1
There are various event present on HTML elements like click, mouse hover etc. if you want to perform some action on hover on HTML element, then browser provide us these methods which will invoked when these action happens.
Upvotes: 0
Reputation: 105
You are only passing the reference to the function if you add () the function will execute every time your webpage is render
Upvotes: 2