Skip to content
Source
Sign inSign up
TanStack/query

docs(framework/angular/guides): add the 'polling' guide #12692

Mergedchromeheartz(GitHub profile, opens in a new tab)merged 2 commits intomain fromrefs/pull/12692/headmerged by TkDodo View on GitHub

Showing 2 changed files with 89 additions and 0 deletions.

x
0 of 2 viewed, 2 left
85 additions and 0 deletionsdocs/framework/angular/guides/polling.mdAdded
View file
@@ -0,0 +1,85 @@
+---
+id: polling
+title: Polling
+ref: docs/framework/react/guides/polling.md
+replace: { '@tanstack/react-query': '@tanstack/angular-query' }
+---
+​
+[//]: # 'Example1'
+​
+```ts
+injectQuery(() => ({
+ queryKey: ['prices'],
+ queryFn: fetchPrices,
+ refetchInterval: 5 * 1000, // every 5 seconds
+}))
+```
+​
+[//]: # 'Example1'
+[//]: # 'Example2'
+​
+```ts
+injectQuery(() => {
+ const jobId = this.jobId()
+​
+ return {
+ queryKey: ['job', jobId],
+ queryFn: () => fetchJobStatus(jobId),
+ refetchInterval: (query) => {
+ // Stop polling once the job finishes
+ if (query.state.data?.status === 'complete') return false