Hacker News new | ask | show | jobs
by esquevin 2160 days ago
Exemples would be welcome here as I've a strong belief that hooks made react components cleaner / shorter
1 comments

For one thing you may not use the ref attribute on function components because they don’t have instances. That means the component can't have a .focus() method for example.

For simple components hooks may be fine. For more complex ones I prefer classes.

I believe the useRef hook is used for this problem:

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

The example even uses .focus()

Maybe I misunderstood, but isn't this what `React.forwardRef` is for?
along with useImperativeHandle for writing your own imperative functions like focus() or whatever