|
Download react-query/docs/framework/angular/guides/placeholder-query-data.md from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.45 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-query/docs/framework/angular/guides/placeholder-query-data.md
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-query/docs/framework/angular/guides/placeholder-query-data.md
-
curl -L -o placeholder-query-data.md https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-query/docs/framework/angular/guides/placeholder-query-data.md
1.45 kB
| id: placeholder-query-data | |
| title: Placeholder Query Data | |
| ref: docs/framework/react/guides/placeholder-query-data.md | |
| [//]: # 'ExampleValue' | |
| ```ts | |
| class TodosComponent { | |
| result = injectQuery(() => ({ | |
| queryKey: ['todos'], | |
| queryFn: () => fetch('/todos'), | |
| placeholderData: placeholderTodos, | |
| })) | |
| } | |
| ``` | |
| [//]: # 'ExampleValue' | |
| [//]: # 'Memoization' | |
| [//]: # 'Memoization' | |
| [//]: # 'ExampleFunction' | |
| ```ts | |
| class TodosComponent { | |
| result = injectQuery(() => ({ | |
| queryKey: ['todos', id()], | |
| queryFn: () => fetch(`/todos/${id}`), | |
| placeholderData: (previousData, previousQuery) => previousData, | |
| })) | |
| } | |
| ``` | |
| [//]: # 'ExampleFunction' | |
| [//]: # 'ExampleCache' | |
| ```ts | |
| export class BlogPostComponent { | |
| // Until Angular supports signal-based inputs, we have to set a signal | |
| @Input({ required: true, alias: 'postId' }) | |
| set _postId(value: number) { | |
| this.postId.set(value) | |
| } | |
| postId = signal(0) | |
| queryClient = inject(QueryClient) | |
| result = injectQuery(() => ({ | |
| queryKey: ['blogPost', this.postId()], | |
| queryFn: () => fetch(`/blogPosts/${this.postId()}`), | |
| placeholderData: () => { | |
| // Use the smaller/preview version of the blogPost from the 'blogPosts' | |
| // query as the placeholder data for this blogPost query | |
| return queryClient | |
| .getQueryData(['blogPosts']) | |
| ?.find((d) => d.id === this.postId()) | |
| }, | |
| })) | |
| } | |
| ``` | |
| [//]: # 'ExampleCache' | |
| [//]: # 'Materials' | |
| [//]: # 'Materials' | |