3 ms·
We're slowly refactoring our class-heavy React app to functional components with hooks. One thing we haven't been able to replace, though, are classes that dep
by jtreminio 7y ago
We're slowly refactoring our class-heavy React app to functional components with hooks.
One thing we haven't been able to replace, though, are classes that depend on refs. How to do this, since there's no instance with functions like there are with classes?
- bcyn 7y agouseRef was designed for this purpose: https://reactjs.org/docs/hooks-reference.html#useref https://reactjs.org/docs/hooks-reference.html#useref If you ran into something that isn't quite covered by this hook, I'm also curious! Can you write a minimal example in codesandbox and share?
- acemarke 7y agoThat's what the very-rarely-used `useImperativeHandle` hook is for - exposing "instance methods" from function components: https://reactjs.org/docs/hooks-reference.html#useimperativehandle https://reactjs.org/docs/hooks-reference.html#useimperativeh...