react-ref

0.0.1 • Public • Published

react-ref

👉 Set reference to an element in React components

Made with ❤ at @outlandish

npm version js-standard-style

Install

API

npm install --save react-ref

CLI

npm install --global react-ref

Import

// ES6
import ref from 'react-ref'
// CommonJS
var ref = require('react-ref')

Usage

ref(instance, name)

  • instance {Object} React component
  • name {String} Name of property to attach element reference

Returns a function.

Example:

class Input extends React.Component {
  focus () {
    this.input.focus()  
  }
  
  clear () {
    this.input.value = ''  
  }
  
  render () {
    return (
      <div className='Input'>
        <input type='text' ref={ref(this, 'input')} />
      </div>
    )  
  }
}

Contributing

All pull requests and issues welcome!

If you're not sure how, check out Kent C. Dodds' great video tutorials on egghead.io!

Author & License

react-ref was created by Sam Gluck and is released under the MIT license.

Readme

Keywords

Package Sidebar

Install

npm i react-ref

Weekly Downloads

3

Version

0.0.1

License

MIT

Last publish

Collaborators

  • sdgluck