mirror of
https://github.com/TanStack/query.git
synced 2026-11-16 22:50:20 +00:00
* chore(*): adopt '@tanstack/oxlint-config' and '@tanstack/oxfmt-config', and fix the newly reported lint errors * chore(pnpm-lock.yaml): run 'pnpm dedupe' * chore(scripts): move 'oxlint/plugin.ts' to 'oxlint-plugin.ts' to match the flat layout of 'scripts' * chore(pnpm-workspace.yaml): update '@typescript-eslint/parser' and '@typescript-eslint/rule-tester' to '^8.72.1' to match the deduped '@typescript-eslint/utils' |
History
|
|
|---|---|---|
| .. | ||
| .devcontainer | ||
| public | ||
| src | ||
| .gitignore | ||
| angular.json | ||
| eslint.config.js | ||
| package.json | ||
| README.md | ||
| tsconfig.app.json | ||
| tsconfig.json | ||
TanStack Angular 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/app/services/tasks/queries.tshas two@Injectableclasses:TasksQueries, whoselist()returnsqueryOptions, andTasksMutations, whosecreate()anddeleteAll()returnmutationOptions. Both convert theHttpClientcalls fromsrc/app/services/tasks/api.tswithlastValueFrom.src/app/components/auto-refetching.component.tsspreadslist()intoinjectQuerywithrefetchInterval: this.intervalMs(), so changing theintervalMssignal from the input changes the polling rate. The template lights a dot whileisFetching()istrue.- In
src/app/components/auto-refetching.component.ts,addMutationandclearMutationare created withinjectMutation, and both invalidate the list'squeryKeyon success. src/app/interceptor/tasks-mock.interceptor.tsis anHttpInterceptorFn, registered withwithInterceptorsinsrc/app/app.config.ts, that answers/api/tasksfromlocalStorageafter 100 ms forGET,POSTandDELETE.
To run this example:
npm installnpm start