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

Providing a react Ref to scrollerRef is generating an error

Open Ethorsen opened this issue 4 years ago • 2 comments

A react ref created with React.createRef/useRef will spit out an error if given directly to scrollerRef prop;

This will generate an error

const scrollerRef = useRef();
<Virtuoso
   scrollerRef={scrollerRef}

Work around for now, give a callback function

const scrollerRef = useRef();
<Virtuoso
   scrollerRef={(ref) => { scrollerRef.current = ref; }}

https://codesandbox.io/s/long-pine-e9g8g?file=/src/App.js

Ethorsen avatar Jan 27 '21 19:01 Ethorsen

Can confirm that - it does not accept a react ref. The TS signature and the docs describe that. The workaround is not that much of a problem, but I am open to PRs.

petyosi avatar Jan 27 '21 19:01 petyosi

You should memoize that callback

const handleScrollerRef = useCallback((ref) => {
  scrollerRef.current = ref;
}, []);

gajus avatar Dec 06 '21 14:12 gajus