examples/preact/auto-refetching
| Name | Last commit message | Last commit date |
|---|---|---|
| .. | ||
README.md
TanStack Preact Query Auto Refetching Example#
A todo list that polls the server with refetchInterval. Adding a todo or clearing the list invalidates the query.
How it works#
src/services/todos/queries.tsdefinestodosQueries.list(), aqueryOptionsfactory keyed by['todos', 'list'], andtodosMutations.create()andtodosMutations.deleteAll()withmutationOptions.src/App.tsxpasses the list query touseQuerywithrefetchIntervalset from the interval input (1000 ms by default), and shows a dot whileisFetchingistrue.- Both mutations run through
useMutationand callqueryClient.invalidateQueries({ queryKey: todosQueries.all() })inonSuccess. src/mocks.tsis an MSW handler for/api/datathat adds or clears items in a list stored inlocalStorage, so changes show up in other tabs on the next refetch.
To run this example:
npm installnpm run dev