Skip to content

Instantly share code, notes, and snippets.

@maullerz
Last active September 30, 2016 14:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maullerz/0f8b2ec9543ae08f151e738f3859b7fe to your computer and use it in GitHub Desktop.
Save maullerz/0f8b2ec9543ae08f151e738f3859b7fe to your computer and use it in GitHub Desktop.

ESLint Rule - No .bind() or Arrow Functions in JSX Props

1. Standard

  <... onClick={this.handler.bind(this)} .../>

2. Arrow function

  <... onClick={() => this.handler()} .../>

3. ::-binding sugar (babel preset stage-0)

  <... onClick={::this.handler} .../>
  constructor(props) {
    this.handler = this.handler.bind(this)
  }
  ...
  <... onClick={this.handler} .../>
	handler = (e) => {
	  ...
	}
	...
	<... onClick={this.handler} .../> .../>
  @autobind
  handler() {
    ...
  }
  ...
  <... onClick={this.handler} .../>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment