examples/preact/prefetching-preact-iso
| Name | Last commit message | Last commit date |
|---|---|---|
| .. | ||
README.md
TanStack Preact Query Prefetching Example (preact-iso)#
Prefetches a character when you hover its link, so the detail view opens without a loading state.
Built with preact-iso.
How it works#
src/services/characters/queries.tsdefinescharactersQueries.list()andcharactersQueries.detail(id)withqueryOptions.detailusesskipTokenwhenidisundefined.- In
src/Home.tsx, eachCharacterItemcallsqueryClient.query({ ...charactersQueries.detail(char.id), staleTime: 10 * 1000 })on mouse enter or focus. It also subscribes withuseQueryandenabled: false, so the name turns bold once the character is cached. src/Character.tsxis the/character/:idroute fromsrc/App.tsx(preact-iso). It reads the id withuseRouteand callsuseQuery(charactersQueries.detail(...)), which renders without a loading state when the character was prefetched.
To run this example:
npm installnpm run dev