examples/solid/prefetching-solid-start2
| Name | Last commit message | Last commit date |
|---|---|---|
| .. | ||
README.md
TanStack Solid Query Prefetching Example (SolidStart)#
Prefetches a character when you hover its link, so the detail view opens without a loading state.
Built with SolidStart.
How it works#
src/services/characters/queries.tsdefinescharactersQueries.list()andcharactersQueries.detail(id)withqueryOptions. The detail options useskipTokenwhen there is noid.src/services/characters/api.tsfetches characters from the Rick and Morty API after a 500 ms delay.- In
src/routes/index.tsx, eachCharacterItemcallsqueryClient.query(...)with a 10-secondstaleTimeonmouseenterandfocusin, so a character is fetched again only when its cached data is older than that. AuseQuerywithenabled: falseonly observes the cache and turns the name bold once the data is there. src/routes/character/[id].tsxreads the samecharactersQueries.detail(id)withuseQuery, so a prefetched character renders without a loading state.
To run this example:
npm installnpm run dev