Showing posts with label Call Javascript function from ReactJS. Show all posts
Showing posts with label Call Javascript function from ReactJS. Show all posts

Thursday, March 5, 2020

Call Javascript function from ReactJS

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>

Popular Posts