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

README.md

17 lines1.0 KB

1# TanStack Solid Query Auto Refetching Example (SolidStart)
2​
3A todo list that polls the server with `refetchInterval`. Adding a todo or clearing the list invalidates the query.
4​
5Built with [SolidStart](https://start.solidjs.com).
6​
7## How it works
8​
9- `src/services/todos/queries.ts` defines `todosQueries.list()` with `queryOptions`, keyed by `['todos', 'list']`, and `todosMutations.create()` and `todosMutations.deleteAll()` with `mutationOptions`.
10- `src/services/todos/api.ts` keeps the list in server memory. Each function is a SolidStart server function marked with `'use server'`.
11- `src/routes/index.tsx` passes the list options to `useQuery` with `refetchInterval` bound to a signal, so changing the interval input changes how often the query refetches. Both mutations call `queryClient.invalidateQueries({ queryKey: todosQueries.all() })` in `onSuccess`.
12- `src/app.tsx` creates the `QueryClient` and provides it with `QueryClientProvider` around the SolidStart router.
13​
14To run this example:
15​
16- `npm install`
17- `npm run dev`