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

TypeError: Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element'.

Open barchambeault-lightbox opened this issue 1 year ago • 4 comments

If I add

  const ref = useRef<HTMLDivElement>() as React.MutableRefObject<HTMLInputElement>;
  const { events } = useDraggable(ref, {
    applyRubberBandEffect: true,
  });

and

<div ref={ref}></div>

then my page blows up with the error in the title of this issue. any ideas?

barchambeault-lightbox avatar Jul 31 '23 23:07 barchambeault-lightbox

Ref cant be empty, needs a child element.

visualcohol avatar Aug 09 '23 22:08 visualcohol

Hi all, I also faced this issue and needed the hook to not crash the page even if the ref was invalid so I forked this project and published a safe version here. Install it with npm i react-use-draggable-scroll-safe

vsg24 avatar Feb 04 '24 22:02 vsg24

Try

  const ref = useRef<HTMLDivElement>() as React.MutableRefObject<HTMLInputElement>;
  const { events } = useDraggable(ref, {
    applyRubberBandEffect: true,
    isMounted: !!ref.current,
  });

CptMaumau avatar Feb 15 '24 05:02 CptMaumau

I had the same issue, with the same error message. I tried out the solution from @CptMaumau and that worked. It seemed like the ref wasn't rendered when I was calling the hook. So that made the fix for it.

I think we can close this issue then?

fredrikj31 avatar Feb 29 '24 12:02 fredrikj31