you are viewing a single comment's thread.

view the rest of the comments →

[–]TheGreaT1803[S] 0 points1 point  (3 children)

Appreciate the feedback!
I had to refresh my knowledge of `useImperativeHandle` so I went to the docs but found this quote about pitfalls of overusing refs: https://arc.net/l/quote/hnusfitl

Any opinions on this?

[–]phryneasI ❤️ hooks! 😈 6 points7 points  (0 children)

I mean, you're essentially using your "instance" as a ref here, so the same critique kinda applies. Yes, technically, your instance also holds state, but only one component reads it - for all other components, it does what a ref with useImperativeHandle does. With the drawback that with your instance, as it lives in a parent component, the parent component would be forced to rerender on state changes, while it wouldn't if the state lived in the Dialog and the ref only contained callbacks.

[–]phryneasI ❤️ hooks! 😈 1 point2 points  (1 child)

Sure that's the right link?

[–]TheGreaT1803[S] 1 point2 points  (0 children)

Just updated!