@chbrown/bind
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

bind

latest version published to npm

@bind decorator for TypeScript.

Install

npm install -S @chbrown/bind

Example

import bind from '@chbrown/bind'

class ClickCounter extends React.Component<{}, {clicks: number}> {
  state: {clicks: number} = {clicks: 0}
  @bind
  onClick(ev: React.FormEvent) {
    this.setState(({clicks}) => ({clicks: clicks + 1}))
  }
  render() {
    const {clicks} = this.state
    return (
      <div>
        <button onClick={this.onClick}>Click here</button>
        <p>Clicked {clicks} times</p>
      </div>
    )
  }
}

License

Copyright 2018 Christopher Brown. MIT Licensed.

Dependents (0)

Package Sidebar

Install

npm i @chbrown/bind

Weekly Downloads

11

Version

1.0.0

License

MIT

Unpacked Size

1.91 kB

Total Files

4

Last publish

Collaborators

  • chbrown