@chbrown/bind
v1.0.0
Published
@bind decorator
Downloads
270
Readme
bind
@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.