import { createRoot } from "react-dom/client"; import { useRef, useState, useEffect } from "react"; function App() { const buttonRef = useRef(); const mouseOverTimeout = useRef(); const [tooltipMeta, setTooltipMeta] = useState({ x: 0, y: 0, height: 0, width: 0, show: false, }); const onMouseOver = () => { mouseOverTimeout.current = setTimeout(() => { const bounding = buttonRef.current.getBoundingClientRect(); setTooltipMeta({ x: bounding.x, y: bounding.y, height: bounding.height, width: bounding.width, show: true, }); }, 1000); }; const onMouseLeave = () => { setTooltipMeta({ x: 0, y: 0, height: 0, width: 0, show: false, }); clearTimeout(mouseOverTimeout.current); }; useEffect(() => { return () => { clearTimeout(mouseOverTimeout.current); }; }, []); return (