Open History to see the last commit
1# TanStack React Query React Native Example
2β
3A movies app for React Native (Expo). Queries refetch when the app comes to the foreground and when the network reconnects, through `focusManager` and `onlineManager`, and support pull to refresh.
4β
5Built with [Expo](https://expo.dev).
6β
7## How it works
8β
9- `src/services/movies/queries.ts` defines `moviesQueries.list()` and `moviesQueries.detail(title)` with `queryOptions`. `src/services/movies/api.ts` reads `src/data/movies.json` after a random delay of up to about 2 seconds.
10- `App.tsx` calls `focusManager.setFocused` from the `AppState` listener in `src/hooks/useAppState.ts`, and `src/hooks/useOnlineManager.ts` feeds NetInfo's connection state into `onlineManager.setEventListener`. Both are skipped on web, where the browser events already cover this.
11- `src/screens/MoviesListScreen.tsx` reads `useQuery(moviesQueries.list())`, supports pull to refresh through `src/hooks/useRefreshByUser.ts`, and uses `src/hooks/useRefreshOnFocus.ts` to call `queryClient.refetchQueries({ stale: true, type: 'active' })` when the screen regains navigation focus.
12- `src/screens/MovieDetailsScreen.tsx` reads the detail query with a `placeholderData` function that takes the matching movie from the cached list via `queryClient.getQueryData(moviesQueries.list().queryKey)`, so the title and year show while the full details load.
13β
14To run this example:
15β
16- `npm install`
17- `npm start`