examples/svelte/load-more-infinite-scroll-sveltekit
| Name | Last commit message | Last commit date |
|---|---|---|
| .. | ||
README.md
TanStack Svelte Query Load-More Infinite Scroll Example (SvelteKit)#
An infinite list that loads the next page when a "Load more" button is clicked.
Built with SvelteKit.
How it works#
src/lib/services/planets/queries.tsdefinesplanetsQueries.list()withinfiniteQueryOptions, starting atinitialPageParam: 1.getNextPageParamreads thepagesearch param from the response'snextURL and returnsundefinedon the last page.src/lib/services/planets/api.tsfetches a page of planets from SWAPI.src/lib/LoadMore.sveltereads the pages withcreateInfiniteQuery, renders every planet indata.pages, and callsfetchNextPagefrom the "Load More" button whilehasNextPageistrue.src/routes/+layout.sveltecreates theQueryClientwithenabled: browser, so queries only run in the browser.
To run this example:
npm installnpm run dev