Skip to content

Latest commit

 

History

History
40 lines (35 loc) · 847 Bytes

placeholder-query-data.md

File metadata and controls

40 lines (35 loc) · 847 Bytes
id title ref
placeholder-query-data
Placeholder Query Data
docs/react/guides/placeholder-query-data.md
const result = useQuery({
  queryKey: ['todos'],
  queryFn: () => fetch('/todos'),
  placeholderData: placeholderTodos,
})
const result = useQuery({
  queryKey: ['blogPost', blogPostId],
  queryFn: () => fetch(`/blogPosts/${blogPostId}`),
  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 === blogPostId)
  },
})