Skip to content

An ES2016 decorator that efficiently binds your component's unique class methods.

Notifications You must be signed in to change notification settings

zackargyle/react-bind-decorator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-bind-decorator

An ES2016 decorator that autobinds all of the unique class methods that are not React.Component prototype methods. This is lighter, and faster than the core-decorator autobind decorator for React components.

Install

npm install react-bind-decorator --save

Usage:

import reactbind from 'react-bind-decorator';

@reactbind()
class Foo extends React.Component {

    // Bound
    boundMethod(arg, i) { ... }

    // Not bound
    render() {
        return (
            <div>
                { this.props.data.map(this.boundMethod) }
            </div>
        );
    }
}

export default Foo;

Optionally it can be used not as a decorator

class Foo extends React.Component {

    // Bound
    boundMethod(arg, i) { ... }

    // Not bound
    render() {
        return (
            <div>
                { this.props.data.map(this.boundMethod) }
            </div>
        );
    }
}

export default reactbind()(Foo);

Benchmarks

Scripts

script description
npm start run the example on localhost:3000
npm run benchmark run the benchmarks to get average time to render

License

MIT

About

An ES2016 decorator that efficiently binds your component's unique class methods.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •