Skip to content

Commit

Permalink
fix suspense in infinite scrolling (#587)
Browse files Browse the repository at this point in the history
  • Loading branch information
thetarnav authored Mar 23, 2024
2 parents e024b1b + 7ba7e1d commit a832f60
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/large-beans-sort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@solid-primitives/pagination": minor
---

infinite scolling: fix suspense
40 changes: 27 additions & 13 deletions packages/pagination/dev/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ async function fetcher(page: number) {
return elements;
}

const App: Component = () => {
const PaginationDemo: Component = () => {
const [paginationProps, page, setPage] = createPagination({ pages: 100 });
const [pages, infiniteScrollLoader, { end }] = createInfiniteScroll(fetcher);

return (
<div class="flex min-h-screen w-full">
<div class="box-border flex w-1/2 flex-col items-center justify-center space-y-4 bg-gray-800 p-24 text-white">
<div class="wrapper-v">
<h4>Pagination component</h4>
Expand All @@ -32,19 +30,35 @@ const App: Component = () => {
</button>
</div>
</div>
<div class="flex max-h-screen w-1/2 flex-col bg-gray-800 text-white">
<div class="flex h-[10%] items-center justify-center overflow-scroll">
<h1>Infinite Scrolling:</h1>
</div>
<div class="h-[90%] overflow-scroll">
<For each={pages()}>{item => <p>{item}</p>}</For>
<Show when={!end()}>
<h1 use:infiniteScrollLoader>Loading...</h1>
</Show>
</div>
);
};


const InfiniteScrollDemo = () => {
const [pages, infiniteScrollLoader, { end }] = createInfiniteScroll(fetcher);
infiniteScrollLoader;
return (
<div class="flex max-h-screen w-1/2 flex-col bg-gray-800 text-white">
<div class="flex h-[10%] items-center justify-center overflow-scroll">
<h1>Infinite Scrolling:</h1>
</div>
<div class="h-[90%] overflow-scroll">
<For each={pages()}>{item => <p>{item}</p>}</For>
<Show when={!end()}>
<h1 use:infiniteScrollLoader>Loading...</h1>
</Show>
</div>
</div>
);
}

const App: Component = () => {
return (
<div class="flex min-h-screen w-full">
<PaginationDemo />
<InfiniteScrollDemo />
</div>
);
};

export default App;
2 changes: 1 addition & 1 deletion packages/pagination/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ export function createInfiniteScroll<T>(fetcher: (page: number) => Promise<T[]>)
const [contents] = createResource(page, fetcher);

createComputed(() => {
const content = contents();
const content = contents.latest;
if (!content) return;
batch(() => {
if (content.length === 0) setEnd(true);
Expand Down

0 comments on commit a832f60

Please sign in to comment.