examples/react/star-wars-react-router
| Name | Last commit message | Last commit date |
|---|---|---|
| .. | ||
README.md
TanStack React Query Star Wars Example (React Router)#
A multi-page Star Wars app with films and characters, where each page fetches its own data.
Built with React Router.
How it works#
src/services/films/queries.ts,src/services/characters/queries.ts, andsrc/services/planets/queries.tsdefinefilmsQueries,charactersQueries, andplanetsQuerieswithqueryOptions, each keyed under its own domain and fetching from SWAPI.filmsQueries.detail(filmId)usesskipTokenwhenfilmIdisundefined.src/Layout.tsxmaps the React Router routes tosrc/Films.tsx,src/Film.tsx,src/Characters.tsx, andsrc/Character.tsx, and each page callsuseQuerywith thelist()ordetail(id)options it needs.src/Character.tsxrenders aFilmand aHomeworldcomponent that each calluseQuerywith their own detail options, andsrc/Film.tsxdoes the same for each character. A character or film loaded on one page is already cached when the other page needs it.
To run this example:
npm installnpm run dev