Skip to content

helton/react-auto-binder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-auto-binder Build Status

🚀 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.

Install

NPM

$ npm install react-auto-binder --save

Yarn

$ yarn add react-auto-binder

Usage

Example 1:

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)

Example 2:

import React from 'react'
import ReactAutoBinder from 'react-auto-binder'

const App = ReactAutoBinder(
  class 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 App

License

MIT © Helton Carlos de Souza

About

🚀 React Auto Binder

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published