react-use
react-use copied to clipboard
[question]: How can I combine useMeasure with useHoverDirty
I have to listen the container's rect changed, and get the hover state. I get this code:
const [ref, rect] = useMeasure();
const isHovering = useHoverDirty(ref); // No
How to get the ref by useMeasure and transit it into useHoverDirty?
import useRef from 'react'; import useMeasure from 'react-use'; import useHoverDirty from 'react-use-gesture';
function YourComponent() { const [ref, rect] = useMeasure(); const hoverRef = useRef(); //Here create a ref for UseHoverDirty
// Attach the ref to the DOM element obtained from useMeasure hoverRef.current = ref.current;
// Now, you can use the hoverRef for the UseHoverDirty hook const isHovering = useHoverDirty(hoverRef);