add a function call to a react component handler code example
Example 1: react button onclick
import React, { Component } from 'react';
class App extends Component {
constructor(props) {
super(props);
this.sayHello = this.sayHello.bind(this);
}
sayHello() {
alert('Hello!');
}
return (
);
}
export default App;
Example 2: react native function
class Foo extends Component {
handleClick() {
console.log('Click happened');
}
render() {
return ;
}
}