T
TanStack13mo ago
fair-rose

Creating a placeholder

Is there a way to make a placeholder?
const rowVirtualizer = useVirtualizer({
count: rows.length,
getScrollElement: () => rowsRef.current,
estimateSize: (index) => getScaledRowHeight(rows[index].type, fontSize),
getItemKey: (index) => {
return `${rows[index].type}-${rows[index].targetId ?? index}`;
},
overscan: 50,
});
const items = rowVirtualizer.getVirtualItems();
const rowVirtualizer = useVirtualizer({
count: rows.length,
getScrollElement: () => rowsRef.current,
estimateSize: (index) => getScaledRowHeight(rows[index].type, fontSize),
getItemKey: (index) => {
return `${rows[index].type}-${rows[index].targetId ?? index}`;
},
overscan: 50,
});
const items = rowVirtualizer.getVirtualItems();
7 Replies
fair-rose
fair-roseOP13mo ago
I have the known amount of items, there is no loading for data
rival-black
rival-black13mo ago
overscan: 50 is kind of a lot - what's making you feel like you need a placeholder?
fair-rose
fair-roseOP13mo ago
When I scroll fast (just roll the scroll wheel) I get a screen of white, this feels like the overscan isn't working. I did turn down the overscan to 25, which felt more reasonable, since that's about how many rows are visible on the screen. @roddds
rival-black
rival-black12mo ago
Some "screen of white" might be unavoidable if your individual rows take longer to render than the speed you're scrolling with, unfortunately, and it's hard to tell you what else could be going on without repro.
fair-rose
fair-roseOP12mo ago
That's what I was afraid of, I think it's rendering slowness, then app is rather complicated (highly interactive gantt chart)
rival-black
rival-black12mo ago
I wonder if, for each of your virtual items, you could return early with a placeholder like a loading spinner, then replace it with the actual content when the content has finished rendering. It might get tricky if your content doesn't perform any async actions that would make it practical to have fast and a slow version. I'd also recommend probably profiling each of your row elements to see what makes them take so long to render, if it isn't something obvious like waiting for an HTTP response.
unwilling-turquoise
unwilling-turquoise12mo ago
There is isScrolling property on virtualizer instance that you can use for placeholder.

Did you find this page helpful?