Open History to see the last commit
1---
2id: placeholder-query-data
3title: Placeholder Query Data
4ref: docs/framework/react/guides/placeholder-query-data.md
5---
6β
7[//]: # 'ExampleValue'
8β
9```tsx
10const result = useQuery({
11 queryKey: ['todos'],
12 queryFn: () => fetch('/todos'),
13 placeholderData: placeholderTodos,
14})
15```
16β
17[//]: # 'ExampleValue'
18[//]: # 'Memoization'
19[//]: # 'Memoization'
20[//]: # 'ExampleCache'
21β
22```tsx
23const result = useQuery({
24 queryKey: ['blogPost', blogPostId],
25 queryFn: () => fetch(`/blogPosts/${blogPostId}`),
26 placeholderData: () => {
27 // Use the smaller/preview version of the blogPost from the 'blogPosts'
28 // query as the placeholder data for this blogPost query
29 return queryClient
30 .getQueryData(['blogPosts'])
31 ?.find((d) => d.id === blogPostId)
32 },
33})
34```
35β
36[//]: # 'ExampleCache'
37[//]: # 'Materials'
38[//]: # 'Materials'