T
TanStack10mo ago
rare-sapphire

rows are jizzy

i have this
const virtualizer = useVirtualizer({
count: data?.spaces.length ?? 10000,
getScrollElement: () => parentRef.current,
estimateSize: () => 34,
overscan: 20,
enabled: !!data?.spaces,
});
const virtualizer = useVirtualizer({
count: data?.spaces.length ?? 10000,
getScrollElement: () => parentRef.current,
estimateSize: () => 34,
overscan: 20,
enabled: !!data?.spaces,
});
4 Replies
rare-sapphire
rare-sapphireOP10mo ago
<tbody>
{data &&
data.spaces &&
data?.spaces?.length > 0 &&
virtualizer.getVirtualItems().map((virtualRow) => {
const row = table.getRowModel().rows[virtualRow.index];
return (
<tr key={row.id} className="hover:bg-gray-50">
{row.getVisibleCells().map((cell) => (
<td key={cell.id} className="px-6 py-4">
{flexRender(
cell.column.columnDef.cell,
cell.getContext()
)}
</td>
))}
</tr>
);
})}
</tbody>
<tbody>
{data &&
data.spaces &&
data?.spaces?.length > 0 &&
virtualizer.getVirtualItems().map((virtualRow) => {
const row = table.getRowModel().rows[virtualRow.index];
return (
<tr key={row.id} className="hover:bg-gray-50">
{row.getVisibleCells().map((cell) => (
<td key={cell.id} className="px-6 py-4">
{flexRender(
cell.column.columnDef.cell,
cell.getContext()
)}
</td>
))}
</tr>
);
})}
</tbody>
why scrolling is continuous and items are jizzy i am using react-table with react-virtual i have this warning
arning: flushSync was called from inside a lifecycle method. React cannot flush when React is already rendering. Consider moving this call to a scheduler task or micro task. Error Component Stack
arning: flushSync was called from inside a lifecycle method. React cannot flush when React is already rendering. Consider moving this call to a scheduler task or micro task. Error Component Stack
rare-sapphire
rare-sapphireOP10mo ago
rare-sapphire
rare-sapphireOP10mo ago
HELP appreciated i added those
function easeInOutQuint(t: number) {
return t < 0.5 ? 16 * t * t * t * t * t : 1 + 16 * --t * t * t * t * t;
}
const scrollToFn: VirtualizerOptions<any, any>["scrollToFn"] = useCallback(
(offset, canSmooth, instance) => {
const duration = 1000;
const start = parentRef.current?.scrollTop || 0;
const startTime = (scrollingRef.current = Date.now());

const run = () => {
if (scrollingRef.current !== startTime) return;
const now = Date.now();
const elapsed = now - startTime;
const progress = easeInOutQuint(Math.min(elapsed / duration, 1));
const interpolated = start + (offset - start) * progress;

if (elapsed < duration) {
elementScroll(interpolated, canSmooth, instance);
requestAnimationFrame(run);
} else {
elementScroll(interpolated, canSmooth, instance);
}
};

requestAnimationFrame(run);
},
[]
);
function easeInOutQuint(t: number) {
return t < 0.5 ? 16 * t * t * t * t * t : 1 + 16 * --t * t * t * t * t;
}
const scrollToFn: VirtualizerOptions<any, any>["scrollToFn"] = useCallback(
(offset, canSmooth, instance) => {
const duration = 1000;
const start = parentRef.current?.scrollTop || 0;
const startTime = (scrollingRef.current = Date.now());

const run = () => {
if (scrollingRef.current !== startTime) return;
const now = Date.now();
const elapsed = now - startTime;
const progress = easeInOutQuint(Math.min(elapsed / duration, 1));
const interpolated = start + (offset - start) * progress;

if (elapsed < duration) {
elementScroll(interpolated, canSmooth, instance);
requestAnimationFrame(run);
} else {
elementScroll(interpolated, canSmooth, instance);
}
};

requestAnimationFrame(run);
},
[]
);
it improved still gizzy scrolling
rare-sapphire
rare-sapphireOP10mo ago

Did you find this page helpful?