;
}}
`,children:(0,n.jsxs)(l.code,{"data-language":"tsx","data-theme":"default",children:[(0,n.jsxs)(l.span,{className:"line",children:[(0,n.jsx)(l.span,{style:{color:"#F97583"},children:"return"}),(0,n.jsx)(l.span,{style:{color:"#E1E4E8"},children:" ("})]}),`
`,(0,n.jsxs)(l.span,{className:"line",children:[(0,n.jsx)(l.span,{style:{color:"#E1E4E8"},children:" <"}),(0,n.jsx)(l.span,{style:{color:"#79B8FF"},children:"InfiniteScroll"})]}),`
`,(0,n.jsxs)(l.span,{className:"line",children:[(0,n.jsx)(l.span,{style:{color:"#B392F0"},children:" count"}),(0,n.jsx)(l.span,{style:{color:"#F97583"},children:"="}),(0,n.jsx)(l.span,{style:{color:"#E1E4E8"},children:"{count}"})]}),`
`,(0,n.jsxs)(l.span,{className:"line",children:[(0,n.jsx)(l.span,{style:{color:"#B392F0"},children:" estimatedHeight"}),(0,n.jsx)(l.span,{style:{color:"#F97583"},children:"="}),(0,n.jsx)(l.span,{style:{color:"#E1E4E8"},children:"{"}),(0,n.jsx)(l.span,{style:{color:"#79B8FF"},children:"100"}),(0,n.jsx)(l.span,{style:{color:"#E1E4E8"},children:"}"})]}),`
`,(0,n.jsxs)(l.span,{className:"line",children:[(0,n.jsx)(l.span,{style:{color:"#B392F0"},children:" overScan"}),(0,n.jsx)(l.span,{style:{color:"#F97583"},children:"="}),(0,n.jsx)(l.span,{style:{color:"#E1E4E8"},children:"{"}),(0,n.jsx)(l.span,{style:{color:"#79B8FF"},children:"10"}),(0,n.jsx)(l.span,{style:{color:"#E1E4E8"},children:"}"})]}),`
`,(0,n.jsxs)(l.span,{className:"line",children:[(0,n.jsx)(l.span,{style:{color:"#B392F0"},children:" gap"}),(0,n.jsx)(l.span,{style:{color:"#F97583"},children:"="}),(0,n.jsx)(l.span,{style:{color:"#E1E4E8"},children:"{gap}"})]}),`
`,(0,n.jsx)(l.span,{className:"line",children:(0,n.jsx)(l.span,{style:{color:"#E1E4E8"},children:" >"})}),`
`,(0,n.jsxs)(l.span,{className:"line",children:[(0,n.jsx)(l.span,{style:{color:"#E1E4E8"},children:" <"}),(0,n.jsx)(l.span,{style:{color:"#79B8FF"},children:"InfiniteScrollList"}),(0,n.jsx)(l.span,{style:{color:"#E1E4E8"},children:">"})]}),`
`,(0,n.jsxs)(l.span,{className:"line",children:[(0,n.jsx)(l.span,{style:{color:"#E1E4E8"},children:" {("}),(0,n.jsx)(l.span,{style:{color:"#FFAB70"},children:"index"}),(0,n.jsx)(l.span,{style:{color:"#E1E4E8"},children:") "}),(0,n.jsx)(l.span,{style:{color:"#F97583"},children:"=>"}),(0,n.jsx)(l.span,{style:{color:"#E1E4E8"},children:" {"})]}),`
`,(0,n.jsxs)(l.span,{className:"line",children:[(0,n.jsx)(l.span,{style:{color:"#F97583"},children:" return"}),(0,n.jsx)(l.span,{style:{color:"#E1E4E8"},children:" <"}),(0,n.jsx)(l.span,{style:{color:"#85E89D"},children:"div"}),(0,n.jsx)(l.span,{style:{color:"#E1E4E8"},children:">{sentences[index]}"}),(0,n.jsx)(l.span,{style:{color:"#85E89D"},children:"div"}),(0,n.jsx)(l.span,{style:{color:"#E1E4E8"},children:">;"})]}),`
`,(0,n.jsx)(l.span,{className:"line",children:(0,n.jsx)(l.span,{style:{color:"#E1E4E8"},children:" }}"})}),`
`,(0,n.jsxs)(l.span,{className:"line",children:[(0,n.jsx)(l.span,{style:{color:"#E1E4E8"},children:" "}),(0,n.jsx)(l.span,{style:{color:"#79B8FF"},children:"InfiniteScroll"}),(0,n.jsx)(l.span,{style:{color:"#E1E4E8"},children:">"})]})]})})}),`
`,(0,n.jsxs)(l.h2,{id:"props",children:[(0,n.jsx)(l.a,{className:"subheading-anchor","aria-label":"Link to section",href:"#props",children:(0,n.jsx)(l.span,{className:"icon icon-link"})}),"Props"]}),`
`,(0,n.jsxs)(l.table,{children:[(0,n.jsx)(l.thead,{children:(0,n.jsxs)(l.tr,{children:[(0,n.jsx)(l.th,{children:"Name"}),(0,n.jsx)(l.th,{children:"Type"}),(0,n.jsx)(l.th,{children:"Description"})]})}),(0,n.jsxs)(l.tbody,{children:[(0,n.jsxs)(l.tr,{children:[(0,n.jsx)(l.td,{children:"count"}),(0,n.jsx)(l.td,{children:(0,n.jsx)(l.code,{children:"number"})}),(0,n.jsx)(l.td,{children:"The total number of items to virtualize."})]}),(0,n.jsxs)(l.tr,{children:[(0,n.jsx)(l.td,{children:"estimatedHeight"}),(0,n.jsx)(l.td,{children:(0,n.jsx)(l.code,{children:"number"})}),(0,n.jsx)(l.td,{children:"Estimated height of each virtual item."})]}),(0,n.jsxs)(l.tr,{children:[(0,n.jsx)(l.td,{children:"lanes"}),(0,n.jsx)(l.td,{children:(0,n.jsx)(l.code,{children:"number"})}),(0,n.jsx)(l.td,{children:"The number of lanes the list is divided into."})]}),(0,n.jsxs)(l.tr,{children:[(0,n.jsx)(l.td,{children:"overScan"}),(0,n.jsx)(l.td,{children:(0,n.jsx)(l.code,{children:"number"})}),(0,n.jsx)(l.td,{children:"The number of items rendered above and below the visible area. A higher number reduces the chance of blank items during slow rendering but increases the virtualizer's render time."})]}),(0,n.jsxs)(l.tr,{children:[(0,n.jsx)(l.td,{children:"gap"}),(0,n.jsx)(l.td,{children:"number"}),(0,n.jsx)(l.td,{children:"Set's the spacing between items in the virtualized list."})]}),(0,n.jsxs)(l.tr,{children:[(0,n.jsx)(l.td,{children:"header"}),(0,n.jsx)(l.td,{children:(0,n.jsx)(l.code,{children:"ReactNode"})}),(0,n.jsx)(l.td,{children:"Component which is at the top of a virtual list. Including it inside the infinite scroll helps to accurately calculate the scroll restoration position."})]}),(0,n.jsxs)(l.tr,{children:[(0,n.jsx)(l.td,{children:"hasNextPage"}),(0,n.jsx)(l.td,{children:(0,n.jsx)(l.code,{children:"boolean"})}),(0,n.jsx)(l.td,{children:"Determines there is a next page to be fetched in paginated query."})]}),(0,n.jsxs)(l.tr,{children:[(0,n.jsx)(l.td,{children:"loading"}),(0,n.jsx)(l.td,{children:(0,n.jsx)(l.code,{children:"boolean"})}),(0,n.jsx)(l.td,{children:"Signals if a queried data is loading."})]}),(0,n.jsxs)(l.tr,{children:[(0,n.jsx)(l.td,{children:"loadingIndicator"}),(0,n.jsx)(l.td,{children:(0,n.jsx)(l.code,{children:"ReactNode"})}),(0,n.jsx)(l.td,{children:"Component used to represent loading data."})]}),(0,n.jsxs)(l.tr,{children:[(0,n.jsx)(l.td,{children:"scrollElementType"}),(0,n.jsxs)(l.td,{children:[(0,n.jsx)(l.code,{children:"window"})," or ",(0,n.jsx)(l.code,{children:"element"})]}),(0,n.jsx)(l.td,{children:"Type of scroll element for the virtualizer, determining whether it's element-based or window-based."})]}),(0,n.jsxs)(l.tr,{children:[(0,n.jsx)(l.td,{children:"onLoadMore"}),(0,n.jsx)(l.td,{children:(0,n.jsx)(l.code,{children:"() => void"})}),(0,n.jsx)(l.td,{children:"Callback to load more data."})]})]})]}),`
`,(0,n.jsx)(s,{children:(0,n.jsxs)(l.p,{children:["The default value of ",(0,n.jsx)(l.code,{children:"scrollElementType"})," is ",(0,n.jsx)(l.code,{children:"window"})]})}),`
`,(0,n.jsxs)(l.h2,{id:"scroll-restoration",children:[(0,n.jsx)(l.a,{className:"subheading-anchor","aria-label":"Link to section",href:"#scroll-restoration",children:(0,n.jsx)(l.span,{className:"icon icon-link"})}),"Scroll Restoration"]}),`
`,(0,n.jsxs)(l.h3,{id:"usage-1",children:[(0,n.jsx)(l.a,{className:"subheading-anchor","aria-label":"Link to section",href:"#usage-1",children:(0,n.jsx)(l.span,{className:"icon icon-link"})}),"Usage"]}),`
`,(0,n.jsx)(l.div,{"data-rehype-pretty-code-fragment":"",children:(0,n.jsx)(l.pre,{"data-language":"tsx","data-theme":"default",__rawString__:`import {
InfiniteScroll,
InfiniteScrollList,
ScrollRestoration,
} from "/infinite-scroll";
`,children:(0,n.jsxs)(l.code,{"data-language":"tsx","data-theme":"default",children:[(0,n.jsxs)(l.span,{className:"line",children:[(0,n.jsx)(l.span,{style:{color:"#F97583"},children:"import"}),(0,n.jsx)(l.span,{style:{color:"#E1E4E8"},children:" {"})]}),`
`,(0,n.jsx)(l.span,{className:"line",children:(0,n.jsx)(l.span,{style:{color:"#E1E4E8"},children:" InfiniteScroll,"})}),`
`,(0,n.jsx)(l.span,{className:"line",children:(0,n.jsx)(l.span,{style:{color:"#E1E4E8"},children:" InfiniteScrollList,"})}),`
`,(0,n.jsx)(l.span,{className:"line",children:(0,n.jsx)(l.span,{style:{color:"#E1E4E8"},children:" ScrollRestoration,"})}),`
`,(0,n.jsxs)(l.span,{className:"line",children:[(0,n.jsx)(l.span,{style:{color:"#E1E4E8"},children:"} "}),(0,n.jsx)(l.span,{style:{color:"#F97583"},children:"from"}),(0,n.jsx)(l.span,{style:{color:"#9ECBFF"},children:' "/infinite-scroll"'}),(0,n.jsx)(l.span,{style:{color:"#E1E4E8"},children:";"})]})]})})}),`
`,(0,n.jsx)(l.div,{"data-rehype-pretty-code-fragment":"",children:(0,n.jsx)(l.pre,{"data-language":"tsx","data-theme":"default",__rawString__:`return (
{(index) => {
return
{sentences[index]}
;
}}
`,children:(0,n.jsxs)(l.code,{"data-language":"tsx","data-theme":"default",children:[(0,n.jsxs)(l.span,{className:"line",children:[(0,n.jsx)(l.span,{style:{color:"#F97583"},children:"return"}),(0,n.jsx)(l.span,{style:{color:"#E1E4E8"},children:" ("})]}),`
`,(0,n.jsxs)(l.span,{className:"line",children:[(0,n.jsx)(l.span,{style:{color:"#E1E4E8"},children:" <"}),(0,n.jsx)(l.span,{style:{color:"#79B8FF"},children:"InfiniteScroll"})]}),`
`,(0,n.jsxs)(l.span,{className:"line",children:[(0,n.jsx)(l.span,{style:{color:"#B392F0"},children:" count"}),(0,n.jsx)(l.span,{style:{color:"#F97583"},children:"="}),(0,n.jsx)(l.span,{style:{color:"#E1E4E8"},children:"{count}"})]}),`
`,(0,n.jsxs)(l.span,{className:"line",children:[(0,n.jsx)(l.span,{style:{color:"#B392F0"},children:" estimatedHeight"}),(0,n.jsx)(l.span,{style:{color:"#F97583"},children:"="}),(0,n.jsx)(l.span,{style:{color:"#E1E4E8"},children:"{"}),(0,n.jsx)(l.span,{style:{color:"#79B8FF"},children:"100"}),(0,n.jsx)(l.span,{style:{color:"#E1E4E8"},children:"}"})]}),`
`,(0,n.jsxs)(l.span,{className:"line",children:[(0,n.jsx)(l.span,{style:{color:"#B392F0"},children:" overScan"}),(0,n.jsx)(l.span,{style:{color:"#F97583"},children:"="}),(0,n.jsx)(l.span,{style:{color:"#E1E4E8"},children:"{"}),(0,n.jsx)(l.span,{style:{color:"#79B8FF"},children:"10"}),(0,n.jsx)(l.span,{style:{color:"#E1E4E8"},children:"}"})]}),`
`,(0,n.jsxs)(l.span,{className:"line",children:[(0,n.jsx)(l.span,{style:{color:"#B392F0"},children:" gap"}),(0,n.jsx)(l.span,{style:{color:"#F97583"},children:"="}),(0,n.jsx)(l.span,{style:{color:"#E1E4E8"},children:"{gap}"})]}),`
`,(0,n.jsx)(l.span,{className:"line",children:(0,n.jsx)(l.span,{style:{color:"#E1E4E8"},children:" >"})}),`
`,(0,n.jsxs)(l.span,{className:"line",children:[(0,n.jsx)(l.span,{style:{color:"#E1E4E8"},children:" <"}),(0,n.jsx)(l.span,{style:{color:"#79B8FF"},children:"ScrollRestoration"}),(0,n.jsx)(l.span,{style:{color:"#E1E4E8"},children:">"})]}),`
`,(0,n.jsxs)(l.span,{className:"line",children:[(0,n.jsx)(l.span,{style:{color:"#E1E4E8"},children:" <"}),(0,n.jsx)(l.span,{style:{color:"#79B8FF"},children:"InfiniteScrollList"}),(0,n.jsx)(l.span,{style:{color:"#E1E4E8"},children:">"})]}),`
`,(0,n.jsxs)(l.span,{className:"line",children:[(0,n.jsx)(l.span,{style:{color:"#E1E4E8"},children:" {("}),(0,n.jsx)(l.span,{style:{color:"#FFAB70"},children:"index"}),(0,n.jsx)(l.span,{style:{color:"#E1E4E8"},children:") "}),(0,n.jsx)(l.span,{style:{color:"#F97583"},children:"=>"}),(0,n.jsx)(l.span,{style:{color:"#E1E4E8"},children:" {"})]}),`
`,(0,n.jsxs)(l.span,{className:"line",children:[(0,n.jsx)(l.span,{style:{color:"#F97583"},children:" return"}),(0,n.jsx)(l.span,{style:{color:"#E1E4E8"},children:" <"}),(0,n.jsx)(l.span,{style:{color:"#85E89D"},children:"div"}),(0,n.jsx)(l.span,{style:{color:"#E1E4E8"},children:">{sentences[index]}"}),(0,n.jsx)(l.span,{style:{color:"#85E89D"},children:"div"}),(0,n.jsx)(l.span,{style:{color:"#E1E4E8"},children:">;"})]}),`
`,(0,n.jsx)(l.span,{className:"line",children:(0,n.jsx)(l.span,{style:{color:"#E1E4E8"},children:" }}"})}),`
`,(0,n.jsxs)(l.span,{className:"line",children:[(0,n.jsx)(l.span,{style:{color:"#E1E4E8"},children:" "}),(0,n.jsx)(l.span,{style:{color:"#79B8FF"},children:"ScrollRestoration"}),(0,n.jsx)(l.span,{style:{color:"#E1E4E8"},children:">"})]}),`
`,(0,n.jsxs)(l.span,{className:"line",children:[(0,n.jsx)(l.span,{style:{color:"#E1E4E8"},children:" "}),(0,n.jsx)(l.span,{style:{color:"#79B8FF"},children:"InfiniteScroll"}),(0,n.jsx)(l.span,{style:{color:"#E1E4E8"},children:">"})]})]})})}),`
`,(0,n.jsxs)(l.h3,{id:"props-1",children:[(0,n.jsx)(l.a,{className:"subheading-anchor","aria-label":"Link to section",href:"#props-1",children:(0,n.jsx)(l.span,{className:"icon icon-link"})}),"Props"]}),`
`,(0,n.jsxs)(l.table,{children:[(0,n.jsx)(l.thead,{children:(0,n.jsxs)(l.tr,{children:[(0,n.jsx)(l.th,{children:"Name"}),(0,n.jsx)(l.th,{children:"Type"}),(0,n.jsx)(l.th,{children:"Description"})]})}),(0,n.jsxs)(l.tbody,{children:[(0,n.jsxs)(l.tr,{children:[(0,n.jsx)(l.td,{children:"scrollConfigStorageKey"}),(0,n.jsx)(l.td,{children:(0,n.jsx)(l.code,{children:"string"})}),(0,n.jsx)(l.td,{children:"Key used to store scroll restoration configuration."})]}),(0,n.jsxs)(l.tr,{children:[(0,n.jsx)(l.td,{children:"lastScrollRestorationKey"}),(0,n.jsx)(l.td,{children:(0,n.jsx)(l.code,{children:"string"})}),(0,n.jsx)(l.td,{children:"Last scroll restoration prevents scroll restoration unless the user navigates back to the last key they visited."})]})]})]}),`
`,(0,n.jsxs)(l.h2,{id:"examples",children:[(0,n.jsx)(l.a,{className:"subheading-anchor","aria-label":"Link to section",href:"#examples",children:(0,n.jsx)(l.span,{className:"icon icon-link"})}),"Examples"]}),`
`,(0,n.jsxs)(l.h3,{id:"element-based-scroll",children:[(0,n.jsx)(l.a,{className:"subheading-anchor","aria-label":"Link to section",href:"#element-based-scroll",children:(0,n.jsx)(l.span,{className:"icon icon-link"})}),"Element based scroll"]}),`
`,(0,n.jsx)(a,{name:"infinite-scroll-element-demo",children:(0,n.jsx)(l.div,{"data-rehype-pretty-code-fragment":"",children:(0,n.jsx)(l.pre,{"data-language":"tsx","data-theme":"default",__rawString__:`import * as React from "react";
import { faker } from "@faker-js/faker";
import {
QueryClient,
QueryClientProvider,
useInfiniteQuery,
} from "@tanstack/react-query";
import {
InfiniteScroll,
InfiniteScrollList,
} from "@/components/ui/infinite-scroll";
const queryClient = new QueryClient();
const randomNumber = (min: number, max: number) =>
faker.number.int({ min, max });
async function fetchServerPage(
limit: number,
offset: number = 0
): Promise<{ rows: Array; nextOffset: number }> {
const rows = new Array(limit)
.fill(0)
.map(() => faker.lorem.sentence(randomNumber(20, 70)));
await new Promise((r) => setTimeout(r, 500));
return { rows, nextOffset: offset + 1 };
}
function InfiniteScrollElement() {
const {
status,
data,
error,
isFetchingNextPage,
fetchNextPage,
hasNextPage,
} = useInfiniteQuery({
queryKey: ["projects"],
queryFn: (ctx) => fetchServerPage(10, ctx.pageParam),
getNextPageParam: (lastGroup) => lastGroup.nextOffset,
initialPageParam: 0,
});
const allRows = data ? data.pages.flatMap((d) => d.rows) : [];
return (