|
Download react-query/docs/framework/angular/guides/parallel-queries.md from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.5 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-query/docs/framework/angular/guides/parallel-queries.md
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-query/docs/framework/angular/guides/parallel-queries.md
-
curl -L -o parallel-queries.md https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-query/docs/framework/angular/guides/parallel-queries.md
1.5 kB
| id: parallel-queries | |
| title: Parallel Queries | |
| ref: docs/framework/react/guides/parallel-queries.md | |
| replace: | |
| { | |
| 'If the number of queries you need to execute is changing from render to render, you cannot use manual querying since that would violate the rules of hooks. Instead, ': '', | |
| 'hook': 'function', | |
| 'React': 'Angular', | |
| 'hooks': 'functions', | |
| 'useQuery': 'injectQuery', | |
| 'useInfiniteQuery': 'injectInfiniteQuery', | |
| 'useQueries': 'injectQueries', | |
| } | |
| [//]: # 'Example' | |
| ```ts | |
| export class AppComponent { | |
| // The following queries will execute in parallel | |
| usersQuery = injectQuery(() => ({ queryKey: ['users'], queryFn: fetchUsers })) | |
| teamsQuery = injectQuery(() => ({ queryKey: ['teams'], queryFn: fetchTeams })) | |
| projectsQuery = injectQuery(() => ({ | |
| queryKey: ['projects'], | |
| queryFn: fetchProjects, | |
| })) | |
| } | |
| ``` | |
| [//]: # 'Example' | |
| [//]: # 'Info' | |
| [//]: # 'Info' | |
| [//]: # 'DynamicParallelIntro' | |
| TanStack Query provides `injectQueries`, which you can use to dynamically execute as many queries in parallel as you'd like. | |
| [//]: # 'DynamicParallelIntro' | |
| [//]: # 'Example2' | |
| ```ts | |
| export class AppComponent { | |
| users = signal<Array<User>>([]) | |
| // Please note injectQueries is under development and this code does not work yet | |
| userQueries = injectQueries(() => ({ | |
| queries: users().map((user) => { | |
| return { | |
| queryKey: ['user', user.id], | |
| queryFn: () => fetchUserById(user.id), | |
| } | |
| }), | |
| })) | |
| } | |
| ``` | |
| [//]: # 'Example2' | |