Answers for "react bind function to component"

3

react bind function to component

class Foo extends Component {
  constructor(props) {
    super(props);
    this.handleClick = this.handleClick.bind(this);
  }
  handleClick() {
    console.log('Click happened');
  }
  render() {
    return <button onClick={this.handleClick}>Click Me</button>;
  }
}
Posted by: Guest on May-20-2020

Code answers related to "react bind function to component"

Code answers related to "Javascript"

Browse Popular Code Answers by Language