Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

useProgressiveRowLimit.ts

14 lines523 Bytes

1import { startTransition, useEffect, useState } from "react";
2​
3/** Paint initial rows first, then render the rest without blocking input. */
4export function useProgressiveRowLimit(initial: number): number {
5 const [limit, setLimit] = useState(initial);
6 useEffect(() => {
7 if (limit === Number.POSITIVE_INFINITY) return;
8 const frame = requestAnimationFrame(() =>
9 startTransition(() => setLimit(Number.POSITIVE_INFINITY)),
10 );
11 return () => cancelAnimationFrame(frame);
12 }, [limit]);
13 return limit;