News for hackers. Stuff that matters.
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
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)
Re:Common mistakes writing React components with hooks by avery42 on Tuesday July 21, 2020 @10:52AM (#23907251)
Maybe I misunderstood, but isn't this what `React.forwardRef` is for?
Re:Common mistakes writing React components with hooks by evan_ on Tuesday July 21, 2020 @12:44PM (#23908393)
along with useImperativeHandle for writing your own imperative functions like focus() or whatever