Created
September 21, 2016 08:42
-
-
Save jkomyno/9cf14b991df35c92af05a4f87b4fb9f6 to your computer and use it in GitHub Desktop.
No more fatigue binding methods in ReactJS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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