Open History to see the last commit
1# TanStack Lit 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/main.ts` passes the list query to `createQueryController` with `refetchInterval` set from the interval input (1000 ms by default), and shows a dot while `isFetching` is `true`.
9- Both mutations run through `createMutationController` and call `client.invalidateQueries({ queryKey: todosQueries.all() })` in `onSuccess`, using the `client` from the mutation function context.
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`