class HelloJavascript extends Component {
constructor(props) {
super(props);
this.myJavascriptClick = this.myJavascriptClick.bind(this);
}
myJavascriptClick() {
console.log('Click happened');
}
render() {
return <button onClick={this.myJavascriptClick}>Click Me</button>;
}
}
Note:
Above function can also be used like..
myJavascriptClick = () => {
console.log('Click happened');
}
Inline function can be used like below..
<button onClick={() => alert('hello world'))}>
Click me!
</button>
constructor(props) {
super(props);
this.myJavascriptClick = this.myJavascriptClick.bind(this);
}
myJavascriptClick() {
console.log('Click happened');
}
render() {
return <button onClick={this.myJavascriptClick}>Click Me</button>;
}
}
Note:
Above function can also be used like..
myJavascriptClick = () => {
console.log('Click happened');
}
Inline function can be used like below..
<button onClick={() => alert('hello world'))}>
Click me!
</button>
No comments:
Post a Comment