2

I'm trying to reference the scrollable List in react-virtualized by using a ref. But my ref is always showing it's current attribute as undefined. Does anyone know how to use a ref with react-virtualized List?

Here's what I am currently doing, but listRef.current is always undefined:

const listRef = useRef()

<List
      width={350}
      height={400}
      rowCount={listsprings.length}
      rowHeight={100}
      rowRenderer={rowRenderer}
      style={{ outline: 'none' }}
      ref={listRef}
      />
UCAudio
  • 77
  • 1
  • 5

2 Answers2

0

You must use pass callback since it uses LegacyRef.

const listRef = useRef()

<List
      ref={(ref) => { listRef.current = ref }}
      width={350}
      height={400}
      rowCount={listsprings.length}
      rowHeight={100}
      rowRenderer={rowRenderer}
      style={{ outline: 'none' }}

/>
0

when you use ref, you should care for "listRef.current" but not just "listRef"