Open History to see the last commit
TanStack React Query Rick And Morty Example (React Router)#
A multi-page Rick and Morty app with characters and episodes, where each page fetches its own data.
Built with React Router.
How it works#
src/services/characters/queries.ts,src/services/episodes/queries.ts, andsrc/services/locations/queries.tsdefinecharactersQueries,episodesQueries, andlocationsQuerieswithqueryOptions, each keyed under its own domain and fetching from the Rick and Morty API.src/Layout.tsxmaps the React Router routes tosrc/Episodes.tsx,src/Episode.tsx,src/Characters.tsx, andsrc/Character.tsx, and each page callsuseQuerywith thelist()ordetail(id)options it needs.src/Character.tsxrenders anEpisodeand aLocationcomponent that each calluseQuerywith their own detail options, andsrc/Episode.tsxdoes the same for each character. A character or episode opened from one page is already cached when the other page needs it.
To run this example:
npm installnpm run dev