T
TanStack11mo ago
stormy-gold

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
stormy-gold
stormy-goldOP11mo ago
I have the known amount of items, there is no loading for data
broad-brown
broad-brown11mo ago
overscan: 50 is kind of a lot - what's making you feel like you need a placeholder?
stormy-gold
stormy-goldOP11mo 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
broad-brown
broad-brown11mo 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.
stormy-gold
stormy-goldOP11mo ago
That's what I was afraid of, I think it's rendering slowness, then app is rather complicated (highly interactive gantt chart)
broad-brown
broad-brown11mo 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.
ambitious-aqua
ambitious-aqua11mo ago
There is isScrolling property on virtualizer instance that you can use for placeholder.

Did you find this page helpful?