1.0.0 • Published 6 years ago

auto-bind-react v1.0.0

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

auto-bind-react

Automatically bind methods to their class instance for React

Install

npm install auto-bind-react

Usage

import React, {Component} from 'react';
import AutoBind from 'auto-bind-react';

export default class Hello extends Component {
    constructor() {
        super();
        AutoBind(this);
        this.state = {
            slogan: 'I am so cool!'
        };
    }
    say() {
        alert(this.state.slogan);
    }
    render() {
        return (
            <div onClick={this.say}>
                Click me to say hello!
            </div>
        );
    }
}

License

MIT © Wang Sijie