Open History to see the last commit
1# TanStack React Query Playground Example
2β
3A todo list with adjustable `staleTime`, `gcTime` and error rate, to see how queries and mutations react to them.
4β
5## How it works
6β
7- `src/services/todos/queries.ts` defines `todosQueries.list(filter)`, keyed by `['todos', 'list', { filter }]` and passing the query `signal` to the API, and `todosQueries.detail(id)` with `queryOptions`, plus `todosMutations.create()` and `todosMutations.update()` with `mutationOptions`.
8- `src/services/todos/api.ts` keeps the todos in memory, responds after a random delay between `serverConfig.queryTimeMin` and `serverConfig.queryTimeMax`, and rejects at the rate set in `serverConfig.errorRate`.
9- In `src/index.tsx`, the inputs in `Root` update `serverConfig` and call `queryClient.setDefaultOptions` with the chosen `staleTime` and `gcTime`. Each `Todos` list runs `useQuery(todosQueries.list(filter))` with its own filter and shows `failureCount` while retrying, and "Force Refetch All" calls `queryClient.invalidateQueries()`.
10- `EditTodo` and `AddTodo` in `src/index.tsx` run the mutations with `useMutation` and invalidate `todosQueries.lists()` on success. `EditTodo` also writes the saved todo into its detail query with `queryClient.setQueryData`.
11β
12To run this example:
13β
14- `npm install`
15- `npm run dev`