|
Download react-query/docs/framework/angular/guides/disabling-queries.md from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 2.04 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-query/docs/framework/angular/guides/disabling-queries.md
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-query/docs/framework/angular/guides/disabling-queries.md
-
curl -L -o disabling-queries.md https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-query/docs/framework/angular/guides/disabling-queries.md
2.04 kB
| id: disabling-queries | |
| title: Disabling/Pausing Queries | |
| ref: docs/framework/react/guides/disabling-queries.md | |
| replace: { 'useQuery': 'injectQuery' } | |
| [//]: # 'Example' | |
| ```angular-ts | |
| @Component({ | |
| selector: 'todos', | |
| template: `<div> | |
| <button (click)="query.refetch()">Fetch Todos</button> | |
| @if (query.data()) { | |
| <ul> | |
| @for (todo of query.data(); track todo.id) { | |
| <li>{{ todo.title }}</li> | |
| } | |
| </ul> | |
| } @else { | |
| @if (query.isError()) { | |
| <span>Error: {{ query.error().message }}</span> | |
| } @else if (query.isLoading()) { | |
| <span>Loading...</span> | |
| } @else if (!query.isLoading() && !query.isError()) { | |
| <span>Not ready ...</span> | |
| } | |
| } | |
| <div>{{ query.isLoading() ? 'Fetching...' : '' }}</div> | |
| </div>`, | |
| }) | |
| export class TodosComponent { | |
| query = injectQuery(() => ({ | |
| queryKey: ['todos'], | |
| queryFn: fetchTodoList, | |
| enabled: false, | |
| })) | |
| } | |
| ``` | |
| [//]: # 'Example' | |
| [//]: # 'Example2' | |
| ```angular-ts | |
| @Component({ | |
| selector: 'todos', | |
| template: ` | |
| <div> | |
| // 🚀 applying the filter will enable and execute the query | |
| <filters-form onApply="filter.set" /> | |
| <todos-table data="query.data()" /> | |
| </div> | |
| `, | |
| }) | |
| export class TodosComponent { | |
| filter = signal('') | |
| todosQuery = injectQuery(() => ({ | |
| queryKey: ['todos', this.filter()], | |
| queryFn: () => fetchTodos(this.filter()), | |
| enabled: !!this.filter(), | |
| })) | |
| } | |
| ``` | |
| [//]: # 'Example2' | |
| [//]: # 'Example3' | |
| ```angular-ts | |
| import { skipToken, injectQuery } from '@tanstack/query-angular' | |
| @Component({ | |
| selector: 'todos', | |
| template: ` | |
| <div> | |
| // 🚀 applying the filter will enable and execute the query | |
| <filters-form onApply="filter.set" /> | |
| <todos-table data="query.data()" /> | |
| </div> | |
| `, | |
| }) | |
| export class TodosComponent { | |
| filter = signal('') | |
| todosQuery = injectQuery(() => ({ | |
| queryKey: ['todos', this.filter()], | |
| queryFn: this.filter() ? () => fetchTodos(this.filter()) : skipToken, | |
| })) | |
| } | |
| ``` | |
| [//]: # 'Example3' | |