react-auto-binder
v1.0.1
Published
Auto bind custom methods in React components
Downloads
1
Readme
react-auto-binder
:rocket: Auto bind custom methods of your React components
ReactAutoBinder is a higher order component that bind this to all custom methods on your React components (just use ReactAutoBinder(YourComponent)
when export it)
Install
NPM
$ npm install react-auto-binder --save
Yarn
$ yarn add react-auto-binder
Usage
import React from 'react'
import ReactAutoBinder from 'react-auto-binder'
class App extends React.Component {
constructor() {
super()
this.state = {
text: 'default'
}
}
handler() {
this.setState({ text: this.refs.input.value })
}
render() {
return (
<div>
<input type="text" ref="input" onChange={this.handler}/>
<h1>{this.state.text}</h1>
</div>
)
}
}
export default ReactAutoBinder(App)
License
MIT © Helton Carlos de Souza