Skip to content

Commit 1f89482

Browse files
committed
fix(examples): show "Nothing more to load" in infinite scroll example
The loader row was excluded from the virtualizer count when hasNextPage was false, so the end-of-list message never rendered. Always include the extra row and add a stop condition to demonstrate the behavior. Closes #1068
1 parent 5d6acc9 commit 1f89482

File tree

1 file changed

+3
-2
lines changed
  • examples/react/infinite-scroll/src

1 file changed

+3
-2
lines changed

examples/react/infinite-scroll/src/main.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ function App() {
3737
} = useInfiniteQuery({
3838
queryKey: ['projects'],
3939
queryFn: (ctx) => fetchServerPage(10, ctx.pageParam),
40-
getNextPageParam: (lastGroup) => lastGroup.nextOffset,
40+
getNextPageParam: (lastGroup) =>
41+
lastGroup.nextOffset < 5 ? lastGroup.nextOffset : undefined,
4142
initialPageParam: 0,
4243
})
4344

@@ -46,7 +47,7 @@ function App() {
4647
const parentRef = React.useRef<HTMLDivElement>(null)
4748

4849
const rowVirtualizer = useVirtualizer({
49-
count: hasNextPage ? allRows.length + 1 : allRows.length,
50+
count: allRows.length + 1,
5051
getScrollElement: () => parentRef.current,
5152
estimateSize: () => 100,
5253
overscan: 5,

0 commit comments

Comments
 (0)