1.0.13 • Published 3 years ago

react-polyfill-ref v1.0.13

Weekly downloads
5
License
MIT
Repository
github
Last release
3 years ago

react-polyfill-ref

Polyfill for React new ref api

Support

>= react@0.14.9

Usage

import { createRef, forwardRef } from 'react-polyfill-ref';
const ref = createRef();

function App() {
  return (
    <div>
      <input ref={ref} />
      <button onClick={() => ref.current.focus()}>click</button>
    </div>
  );
}

// forwardRef

const ref = createRef();

const Input = forwardRef((props, ref) => {
  return <input ref={ref} />
});

const App = () => {
  return (
    <div>
      <Input ref={ref} />
      <button onClick={() => ref.current.focus()}>click</button>
    </div>
  );
};

For more usage, see https://reactjs.org/docs/refs-and-the-dom.html#creating-refs

Others

You can use it with react-polyfill-context and react-polyfill-hooks