react-use icon indicating copy to clipboard operation
react-use copied to clipboard

[question]: How can I combine useMeasure with useHoverDirty

Open mortalYoung opened this issue 1 year ago • 1 comments

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?

mortalYoung avatar Jan 23 '24 03:01 mortalYoung

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);

Piyushjaiswal19 avatar Feb 08 '24 17:02 Piyushjaiswal19