Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend event handlers with an example of arrow function in class property #56

Open
sejoker opened this issue Apr 8, 2017 · 1 comment

Comments

@sejoker
Copy link

sejoker commented Apr 8, 2017

Based on the description. If project owners are ok enable Stage 2 Babel transformation it is a good alternative to bind in the constructor.

class Switcher extends React.Component {
  constructor(props) {
    super(props);
    this.state = { name: 'React in patterns' };
  }
  render() {
    return (
      <button onClick={ this.onButtonClick }>
        click me
      </button>
    );
  }
  onButtonClick = () => {
    console.log(`Button is clicked inside ${ this.state.name }`);
  }
}

Let me know if you accept the PR.

@cytrowski
Copy link

I suggest moving it even further:

class Switcher extends React.Component {
  state = { name: 'React in patterns' }
  
  render() {
    return (
      <button onClick={ this._buttonClick }>
        click me
      </button>
    )
  }

  handleButtonClick = () => {
    console.log(`Button is clicked inside ${ this.state.name }`)
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants