react-polyfill-ref
v1.0.13
Published
React createRef forwardRef polyfill
Downloads
39
Maintainers
Readme
react-polyfill-ref
Polyfill for React new ref api
Support
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