Open History to see the last commit
TanStack Lit 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/main.tspasses the list query tocreateQueryControllerwithrefetchIntervalset from the interval input (1000 ms by default), and shows a dot whileisFetchingistrue.- Both mutations run through
createMutationControllerand callclient.invalidateQueries({ queryKey: todosQueries.all() })inonSuccess, using theclientfrom the mutation function context. 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