Refactor Tooltip Component to Improve Hover Target Management

- Introduced a variable for hovered targets in the Tooltip component to enhance clarity and maintainability of the hover state management.
- Updated the cleanup logic to directly reference the hovered targets variable, streamlining the event listener removal process.
This commit is contained in:
Tom Butcher 2026-08-21 11:09:27 +01:00
parent 8ff21a69a3
commit 368e2ba9ef

View File

@ -55,6 +55,8 @@ const Tooltip = ({ children, title, content, listenParents = 0 }) => {
const span = spanRef.current
if (!span || listenParents < 1) return
const hoveredTargets = hoveredTargetsRef.current
const handleEnter = (event) => onMouseEnterRef.current(event)
const handleLeave = (event) => onMouseLeaveRef.current(event)
@ -75,7 +77,7 @@ const Tooltip = ({ children, title, content, listenParents = 0 }) => {
parent.removeEventListener('mouseenter', handleEnter)
parent.removeEventListener('mouseleave', handleLeave)
})
hoveredTargetsRef.current.clear()
hoveredTargets.clear()
}
}, [listenParents])