react-virtuoso
react-virtuoso copied to clipboard
Providing a react Ref to scrollerRef is generating an error
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
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.
You should memoize that callback
const handleScrollerRef = useCallback((ref) => {
scrollerRef.current = ref;
}, []);