react-bind-this

1.1.0 • Public • Published

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)

Readme

Keywords

Package Sidebar

Install

npm i react-bind-this

Weekly Downloads

0

Version

1.1.0

License

ISC

Unpacked Size

1.95 kB

Total Files

4

Last publish

Collaborators

  • chilts