Skip to content

Instantly share code, notes, and snippets.

@maullerz maullerz/Bindings.md
Last active Sep 30, 2016

Embed
What would you like to do?

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} .../>

4. Bind in constructor

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

5. Property initializer

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

6. Autobind ES7 decorator

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

* List of items example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.