Files
upstream-tanstack-query/docs/framework/solid/guides/placeholder-query-data.md
upstream-mirror 3a013ccdfe
Some checks failed
autofix.ci / autofix (push) Failing after 4s
Release / Release (push) Has been skipped
GitHub Actions Security Analysis / Run zizmor (push) Failing after 2s
snapshot of https://github.com/TanStack/query.git (main, 2026-09-16; blobs > 131072B omitted)
2026-09-16 01:13:08 +05:00

1.6 KiB

id, title, ref
id title ref
placeholder-query-data Placeholder Query Data docs/framework/react/guides/placeholder-query-data.md
function Todos() {
  const todosQuery = useQuery(() => ({
    queryKey: ['todos'],
    queryFn: () => fetch('/todos'),
    placeholderData: placeholderTodos,
  }))
}

Placeholder Data Memoization

If the process for accessing a query's placeholder data is intensive or just not something you want to perform on every render, you can memoize the value:

function Todos() {
  const placeholderData = createMemo(() => generateFakeTodos())
  const todosQuery = useQuery(() => ({
    queryKey: ['todos'],
    queryFn: () => fetch('/todos'),
    placeholderData: placeholderData(),
  }))
}
const todosQuery = useQuery(() => ({
  queryKey: ['todos', id],
  queryFn: () => fetch(`/todos/${id}`),
  placeholderData: (previousData, previousQuery) => previousData,
}))
function BlogPost(props) {
  const queryClient = useQueryClient()
  const blogPostQuery = useQuery(() => ({
    queryKey: ['blogPost', props.blogPostId],
    queryFn: () => fetch(`/blogPosts/${props.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 === props.blogPostId)
    },
  }))
}