react-use-draggable-scroll
react-use-draggable-scroll copied to clipboard
TypeError: Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element'.
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?
Ref cant be empty, needs a child element.
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
Try
const ref = useRef<HTMLDivElement>() as React.MutableRefObject<HTMLInputElement>;
const { events } = useDraggable(ref, {
applyRubberBandEffect: true,
isMounted: !!ref.current,
});
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?