1.1.0 • Published 6 years ago

react-bind-this v1.1.0

Weekly downloads
1
License
ISC
Repository
github
Last release
6 years ago

React Bind this

Tired of the following in your React class constructors?

this.handleClick = this.handleClick.bind(this)
this.onToggle = this.onToggle.bind(this)
this.onChange = this.onChange.bind(this)

Use react-bind-this and you can do the following instead:

bindThis(this, 'handleClick', 'onToggle', 'onChange')

Done! :)

Usage

Require this module as follows:

const bindThis = require('react-bind-this')

And use inside your constructor function:

class MyComponent extends React.Component {

  constructor(props) {
    super(props)
    bindThis(this, 'handleClick', 'onToggle', 'onChange')
  }

}

Author

Andrew Chilton.

License

ISC.

(Ends)