I am a beginner to React and I tried onClick in these two ways. Can anyone explain the difference between these two?
1st way:-- onClick={() => this.func()}
func(){
alert("Button Clicked");
}
render() {
return (
<div className="App">
<button onClick={() => this.func()}> Click Me </button>
</div>
);
}
2nd way:-- onClick={this.func}
func(){
alert("Button Clicked");
}
render() {
return (
<div className="App">
<button onClick={this.func}> Click Me </button>
</div>
);
}