Skip to content

Instantly share code, notes, and snippets.

@jkomyno
Created September 21, 2016 08:42
Show Gist options
  • Save jkomyno/9cf14b991df35c92af05a4f87b4fb9f6 to your computer and use it in GitHub Desktop.
Save jkomyno/9cf14b991df35c92af05a4f87b4fb9f6 to your computer and use it in GitHub Desktop.
No more fatigue binding methods in ReactJS
class BaseComponent extends React.Component {
_bind(...methods) {
methods.forEach( (method) => this[method] = this[method].bind(this) );
}
}
class ExampleComponent extends BaseComponent {
constructor() {
super();
this._bind('_handleClick', '_handleFoo');
}
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment