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

README.md

15 lines917 Bytes

1# TanStack Preact Query Auto Refetching Example
2​
3A todo list that polls the server with `refetchInterval`. Adding a todo or clearing the list invalidates the query.
4​
5## How it works
6​
7- `src/services/todos/queries.ts` defines `todosQueries.list()`, a `queryOptions` factory keyed by `['todos', 'list']`, and `todosMutations.create()` and `todosMutations.deleteAll()` with `mutationOptions`.
8- `src/App.tsx` passes the list query to `useQuery` with `refetchInterval` set from the interval input (1000 ms by default), and shows a dot while `isFetching` is `true`.
9- Both mutations run through `useMutation` and call `queryClient.invalidateQueries({ queryKey: todosQueries.all() })` in `onSuccess`.
10- `src/mocks.ts` is an MSW handler for `/api/data` that adds or clears items in a list stored in `localStorage`, so changes show up in other tabs on the next refetch.
11​
12To run this example:
13​
14- `npm install`
15- `npm run dev`