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

background-fetching-indicators.md

58 lines1.1 KB

1---
2id: background-fetching-indicators
3title: Background Fetching Indicators
4ref: docs/react/guides/background-fetching-indicators.md
5---
6​
7[//]: # 'Example'
8​
9```ts
10@Component({
11 selector: 'posts',
12 template: `
13 @switch (query.status()) {
14 @case ('pending') {
15 Loading...
16 }
17 @case ('error') {
18 An error has occurred: {{ query.error()?.message }}
19 }
20 @default {
21 @if (query.isFetching()) {
22 Refreshing...
23 }
24 @for (todo of query.data()) {
25 <todo [todo]="todo" />
26 }
27 }
28 }
29 `,
30})
31export class TodosComponent {
32 todosQuery = injectQuery(() => ({
33 queryKey: ['todos'],
34 queryFn: fetchTodos,
35 }))
37```
38​
39[//]: # 'Example'
40[//]: # 'Example2'
41​
42```ts
43import { injectIsFetching } from '@tanstack/angular-query-experimental'
44​
45@Component({
46 selector: 'global-loading-indicator',
47 template: `
48 @if (isFetching()) {
49 <div>Queries are fetching in the background...</div>
50 }
51 `,
52})
53export class GlobalLoadingIndicatorComponent {
54 isFetching = injectIsFetching()
56```
57​
58[//]: # 'Example2'