react-create-ref

1.0.1 • Public • Published

React.createRef() polyfill for React < 16.3

Install

npm install react-create-ref --save

Use

Calls native React.createRef() if it's available (React >= 16.3), calls the polyfill function otherwise (React < 16.3).

import createRef from 'react-create-ref'
 
class Example extends React.Component {
  constructor() {
    this.input = createRef()
  }
 
  render() {
    return (
      <form>
        <input type="text" ref={this.input} />
        <button type="button" onClick={() => this.input.current.focus()} />
      </form>
    )
  }
}

Dependencies (0)

    Dev Dependencies (4)

    Package Sidebar

    Install

    npm i react-create-ref

    Weekly Downloads

    9,498

    Version

    1.0.1

    License

    MIT

    Unpacked Size

    2.57 kB

    Total Files

    5

    Last publish

    Collaborators

    • catamphetamine