Should useHover fire hoverEnd on unmount? #3016
Replies: 1 comment 1 reply
-
This is an interesting case. I can see the benefits to hooking up some cleanup to onHoverEnd, though you should know when your component unmounts and be able to do any cleanup that way. We don't currently do this for any of our interactions, see usePress here https://codesandbox.io/s/priceless-hypatia-pn79kq?file=/src/App.js though I could see it being argued that this is a different case because hovering is passive, where as the press is an action taken, and just because the component unmounted, doesn't actually mean pressing has stopped. I'll check with the team to see if this is something we'd like to have. It'd be helpful in making a case if you could provide a concrete example of why you need this functionality if you do not mind. |
Beta Was this translation helpful? Give feedback.
-
It seems that if you hoist up the state from
useHover
and the component that rendersuseHover
unmounts theonHoverEnd
is not called.This causes lingering states in the app I'm working on. The question I have is should this be the responsibility of the component to clean up the state or should
useHover
be responsible for cleanup? This can be done by callingonHoverEnd
in the cleanup effect whenstate.isHovered === true
.I have an example here what that would look like interactions/src/useHover.ts
Example of components responsibility:
Beta Was this translation helpful? Give feedback.
All reactions