Thank you selbekk for the post.
I'd also like to add to When to use ref using Dan's tweet from yesterday by showing one of the ways to encapsulate an imperative logic.
Dan Abramov @dan_abramov Overlooked pattern: using classes from a function component with useRef Hook.function MyThing() { const ref = useRef() if (!ref.current) { ref.current = new MyClass() } // ...}class MyClass { // ...}Why? For imperative logic like jQuery plugins or logging. 20:34 PM - 13 Mar 2019 38 221
One can extract the imperative logic out of the component and encapsulate in a class using a ref.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Thank you selbekk for the post.
I'd also like to add to When to use ref using Dan's tweet from yesterday by showing one of the ways to encapsulate an imperative logic.
One can extract the imperative logic out of the component and encapsulate in a class using a ref.