You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/framework/angular/typescript.md
+4-2Lines changed: 4 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -174,9 +174,11 @@ computed(() => {
174
174
175
175
## Typing Query Options
176
176
177
-
If you inline query options into `injectQuery`, you'll get automatic type inference. However, you might want to extract the query options into a separate function to share them between `injectQuery` and e.g. `prefetchQuery` or manage them in a service. In that case, you'd lose type inference. To get it back, you can use the `queryOptions` helper:
177
+
If you inline query options into `injectQuery`, you'll get automatic type inference. However, you might want to extract the query options into a separate function to share them between `injectQuery` and e.g. `queryClient.query`, or manage them in a service. In that case, you'd lose type inference. To get it back, you can use the `queryOptions` helper:
@@ -355,7 +363,7 @@ Using React Query with Server Components makes most sense if:
355
363
356
364
It's hard to give general advice on when it makes sense to pair React Query with Server Components and not. **If you are just starting out with a new Server Components app, we suggest you start out with any tools for data fetching your framework provides you with and avoid bringing in React Query until you actually need it.** This might be never, and that's fine, use the right tool for the job!
357
365
358
-
If you do use it, a good rule of thumb is to avoid `queryClient.fetchQuery` unless you need to catch errors. If you do use it, don't render its result on the server or pass the result to another component, even a Client Component one.
366
+
If you do use it, a good rule of thumb is to avoid rendering the result of `queryClient.query`on the server or passing it to another component, even a Client Component one.
359
367
360
368
From the React Query perspective, treat Server Components as a place to prefetch data, nothing more.
361
369
@@ -424,7 +432,7 @@ export function getQueryClient() {
424
432
425
433
> Note: This works in NextJs and Server Components because React can serialize Promises over the wire when you pass them down to Client Components.
426
434
427
-
Then, all we need to do is provide a `HydrationBoundary`, but we don't need to `await` prefetches anymore:
435
+
Then, all we need to do is provide a `HydrationBoundary`, but we don't need to `await`these prefetches anymore:
428
436
429
437
```tsx
430
438
// app/posts/page.tsx
@@ -437,10 +445,12 @@ export default function PostsPage() {
437
445
const queryClient =getQueryClient()
438
446
439
447
// look ma, no await
440
-
queryClient.prefetchQuery({
441
-
queryKey: ['posts'],
442
-
queryFn: getPosts,
443
-
})
448
+
voidqueryClient
449
+
.query({
450
+
queryKey: ['posts'],
451
+
queryFn: getPosts,
452
+
})
453
+
.catch(noop)
444
454
445
455
return (
446
456
<HydrationBoundarystate={dehydrate(queryClient)}>
@@ -504,10 +514,12 @@ export default function PostsPage() {
504
514
const queryClient =getQueryClient()
505
515
506
516
// look ma, no await
507
-
queryClient.prefetchQuery({
508
-
queryKey: ['posts'],
509
-
queryFn: () =>getPosts().then(serialize), // <-- serialize the data on the server
510
-
})
517
+
voidqueryClient
518
+
.query({
519
+
queryKey: ['posts'],
520
+
queryFn: () =>getPosts().then(serialize), // <-- serialize the data on the server
Copy file name to clipboardExpand all lines: docs/framework/react/guides/initial-query-data.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ There are many ways to supply initial data for a query to the cache before you n
8
8
- Declaratively:
9
9
- Provide `initialData` to a query to prepopulate its cache if empty
10
10
- Imperatively:
11
-
-[Prefetch the data using `queryClient.prefetchQuery`](./prefetching.md)
11
+
-[Prefetch the data using `queryClient.query`](./prefetching.md)
12
12
-[Manually place the data into the cache using `queryClient.setQueryData`](./prefetching.md)
13
13
14
14
## Using `initialData` to prepopulate a query
@@ -84,7 +84,7 @@ By default, `initialData` is treated as totally fresh, as if it were just fetche
84
84
85
85
This option allows the staleTime to be used for its original purpose, determining how fresh the data needs to be, while also allowing the data to be refetched on mount if the `initialData` is older than the `staleTime`. In the example above, our data needs to be fresh within 1 minute, and we can hint to the query when the initialData was last updated so the query can decide for itself whether the data needs to be refetched again or not.
86
86
87
-
> If you would rather treat your data as **prefetched data**, we recommend that you use the `prefetchQuery` or `fetchQuery` APIs to populate the cache beforehand, thus letting you configure your `staleTime` independently from your initialData
87
+
> If you would rather treat your data as **prefetched data**, we recommend that you use the `query` api to populate the cache beforehand, thus letting you configure your `staleTime` independently from your `initialData`.
0 commit comments