News for hackers. Stuff that matters.
Re:Frustrations with React Hooks by jtreminio on Tuesday September 10, 2019 @11:15AM (#20929129)
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?

Re:Frustrations with React Hooks by acemarke on Tuesday September 10, 2019 @11:29AM (#20929280)
That's what the very-rarely-used `useImperativeHandle` hook is for - exposing "instance methods" from function components:

https://reactjs.org/docs/hooks-reference.html#useimperativeh...

Re:Frustrations with React Hooks by bcyn on Tuesday September 10, 2019 @11:26AM (#20929245)
useRef was designed for this purpose: 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?