Skip to content

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

@sejoker

Description

@sejoker

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions