Open History to see the last commit
1# TanStack React Query Star Wars Example (React Router)
2β
3A multi-page Star Wars app with films and characters, where each page fetches its own data.
4β
5Built with [React Router](https://reactrouter.com).
6β
7## How it works
8β
9- `src/services/films/queries.ts`, `src/services/characters/queries.ts`, and `src/services/planets/queries.ts` define `filmsQueries`, `charactersQueries`, and `planetsQueries` with `queryOptions`, each keyed under its own domain and fetching from SWAPI. `filmsQueries.detail(filmId)` uses `skipToken` when `filmId` is `undefined`.
10- `src/Layout.tsx` maps the React Router routes to `src/Films.tsx`, `src/Film.tsx`, `src/Characters.tsx`, and `src/Character.tsx`, and each page calls `useQuery` with the `list()` or `detail(id)` options it needs.
11- `src/Character.tsx` renders a `Film` and a `Homeworld` component that each call `useQuery` with their own detail options, and `src/Film.tsx` does the same for each character. A character or film loaded on one page is already cached when the other page needs it.
12β
13To run this example:
14β
15- `npm install`
16- `npm run dev`