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:
parent
8ff21a69a3
commit
368e2ba9ef
@ -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])
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user