Re:Common mistakes writing React components with hooks
by esquevin on Tuesday July 21, 2020 @10:03AM
(#23906849)
Exemples would be welcome here as I've a strong belief that hooks made react components cleaner / shorter
[ Parent
| on HN ]
Re:Common mistakes writing React components with hooks
by flowerlad on Tuesday July 21, 2020 @10:29AM
(#23907046)
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.
Re:Common mistakes writing React components with hooks
by Octoth0rpe on Tuesday July 21, 2020 @10:34AM
(#23907079)
I believe the useRef hook is used for this problem:
https://reactjs.org/docs/hooks-reference.html#useref
The example even uses .focus()
Re:Common mistakes writing React components with hooks
by cnity on Tuesday July 21, 2020 @10:42AM
(#23907143)
That's just not true: https://reactjs.org/docs/forwarding-refs.html