1.0.5 • Published 8 years ago

react-bind-handlers v1.0.5

Weekly downloads
10
License
ISC
Repository
-
Last release
8 years ago

Build Status

react-bind-handlers

Class decorator which binds class methods to instance, so this always refers to an instance

Allows to avoid repetitive bind(this) in React component constructor:

class Component extends React.Component {
    constructor() {
        this.handleOpenBtnTap = this.handleOpenBtnTap.bind(this);
        this.handleCloseBtnTap = this.handleCloseBtnTap.bind(this);
        this.handleMenuItemTap = this.handleMenuItemTap.bind(this);
        ...
    }
}

becomes:

class Component extends React.Component {
    ...
}

export default bindHandlers(Component);

By default all methods with handle* prefix will autobind to this

How to use:

Install:

npm i react-bind-handlers

Import and use:

import { bindHandlers } from 'react-bind-handlers';
class Component extends React.Component {}
export default bindHandlers(Component);
import { bind } from 'react-bind-handlers';
class Component extends React.Component {}
export default bind(regExp)(Component);
1.0.5

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago