Is it okay to call rowVirtualizer.getVirtualItems() multiple times?
I'm looking at examples codesandbox and it feels like you can do something like
const items = rowVirtualizer.getVirtualItems()
and do not call that function 3 times inside the same render. Which begs the question, why is it written this way? My hunch is that this function is probably just an accessor and calling almost the same performance as if it was rowVirtualizer.virtualItems
https://codesandbox.io/s/github/tanstack/virtual/tree/beta/examples/react/infinite-scroll?from-embed=&file=/src/main.tsxCodeSandbox
tanstack-react-virtual-example-infinite-scroll - CodeSandbox
tanstack-react-virtual-example-infinite-scroll using @tanstack/react-virtual, react, react-dom, react-query
1 Reply
conscious-sapphire•3y ago
Based on the source code,
getVirtualItems
is a memoized function, so calling it multiple times shouldn't have any negative impact.