0
Fork 0
mirror of https://github.com/TanStack/query.git synced 2026-11-16 22:50:20 +00:00
query/docs/framework/angular/guides/placeholder-query-data.md
Wonsuk Choi 390de5a8dd
docs(angular-query-experimental): add 'readonly' and use descriptive names for class fields in guide examples (#11445)
* docs(angular-query-experimental): add 'readonly' and use descriptive names for class fields in guide examples

* docs(angular-query-experimental): use descriptive names for class fields in 'placeholder-query-data.md'
2026-09-08 11:39:41 +09:00

1.3 KiB

id title ref
placeholder-query-data Placeholder Query Data docs/framework/react/guides/placeholder-query-data.md
class TodosComponent {
  readonly todosQuery = injectQuery(() => ({
    queryKey: ['todos'],
    queryFn: () => fetch('/todos'),
    placeholderData: placeholderTodos,
  }))
}
class TodosComponent {
  readonly todoQuery = injectQuery(() => ({
    queryKey: ['todos', id()],
    queryFn: () => fetch(`/todos/${id}`),
    placeholderData: (previousData, previousQuery) => previousData,
  }))
}
export class BlogPostComponent {
  postId = input.required<number>()
  readonly queryClient = inject(QueryClient)

  readonly blogPostQuery = 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 this.queryClient
        .getQueryData(['blogPosts'])
        ?.find((d) => d.id === this.postId())
    },
  }))
}