[React] 6. Handling Events
Binding
위처럼 ()를 붙이지 않고 method를 레퍼런스하는 경우, 메서드를 바인드해주어야 한다.
  render() {
    return (
      <button onClick={this.handleClick}>
        {this.state.isToggleOn ? 'ON' : 'OFF'}
      </button>
    );
  }위처럼 ()를 붙이지 않고 method를 레퍼런스하는 경우, 메서드를 바인드해주어야 한다.
 constructor(props) {
    super(props);
    this.state = {isToggleOn: true};
    // This binding is necessary to make `this` work in the callback
    this.handleClick = this.handleClick.bind(this);
  }class LoggingButton extends React.Component {
  // This syntax ensures `this` is bound within handleClick.
  // Warning: this is *experimental* syntax.
  handleClick = () => {
    console.log('this is:', this);
  }
  render() {
    return (
      <button onClick={this.handleClick}>
        Click me
      </button>
    );
  }
}
댓글
댓글 쓰기