examples/solid/ssr-astro
| Name | Last commit message | Last commit date |
|---|---|---|
| .. | ||
README.md
TanStack Solid Query SSR Example (Astro)#
A Pokémon search with keepPreviousData and <Suspense>, rendered as a Solid island.
Built with Astro.
How it works#
src/services/pokemons/queries.tsdefinespokemonsQueries.list()andpokemonsQueries.detail(id)withqueryOptions. The detail options setplaceholderData: keepPreviousDataandthrowOnError: true.src/layouts/MainLayout.astrorendersSolidAppfromsrc/components/SolidApp.tsxas an island withclient:load, passing theidsearch param read insrc/pages/index.astro. Astro runs inoutput: 'server'mode, so the island is rendered on the server first.src/components/SolidApp.tsxcreates theQueryClientand wraps the app inQueryClientProviderand<Suspense>. The side nav and detail view calluseQuerywithselectto reshape the data andreconcileto keep list items stable, and anErrorBoundaryshows errors thrown by the detail query.src/components/Link.tsxandsrc/utils/index.tshandle client-side navigation withhistory.pushStateand a signal that tracks theidsearch param. Anis_server_renderedquery insrc/components/SolidApp.tsxshows whether the current detail was rendered on the server or the client.
To run this example:
npm installnpm run dev