Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

README.md

15 lines1.2 KB

1# TanStack Solid 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)` and `todosQueries.detail(id)` with `queryOptions`, keyed under `['todos', 'list']` and `['todos', 'detail', id]`, and `todosMutations.create()` and `update()` with `mutationOptions`.
8- `src/services/todos/api.ts` simulates a server in memory. Every call waits a random time between `serverConfig.queryTimeMin` and `serverConfig.queryTimeMax` and fails at `serverConfig.errorRate`.
9- `src/index.tsx` binds the inputs to `serverConfig` and calls `queryClient.setDefaultOptions` with the chosen `staleTime` and `gcTime` from a `createEffect`. Each filter list reads its todos with `useQuery`, and "Force Refetch All" calls `queryClient.invalidateQueries()`.
10- The `EditTodo` and `AddTodo` components in `src/index.tsx` run the mutations with `useMutation`. On success they invalidate `todosQueries.lists()`, and saving an edit also writes the result into the detail query with `queryClient.setQueryData`.
11​
12To run this example:
13​
14- `npm install`
15- `npm run dev`