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
- Additionally, you can use the `useQuery().promise` and `React.use()` (Experimental)
12
11
13
12
When using suspense mode, `status` states and `error` objects are not needed and are then replaced by usage of the `React.Suspense` component (including the use of the `fallback` prop and React error boundaries for catching errors). Please read the [Resetting Error Boundaries](#resetting-error-boundaries) and look at the [Suspense Example](../examples/suspense) for more information on how to set up suspense mode.
For more information, check out the [NextJs Suspense Streaming Example](../examples/nextjs-suspense-streaming) and the [Advanced Rendering & Hydration](./advanced-ssr.md) guide.
176
-
177
-
## Using `useQuery().promise` and `React.use()` (Experimental)
178
-
179
-
> To enable this feature, you need to set the `experimental_prefetchInRender` option to `true` when creating your `QueryClient`
180
-
181
-
**Example code:**
182
-
183
-
```tsx
184
-
const queryClient =newQueryClient({
185
-
defaultOptions: {
186
-
queries: {
187
-
experimental_prefetchInRender: true,
188
-
},
189
-
},
190
-
})
191
-
```
192
-
193
-
**Usage:**
194
-
195
-
```tsx
196
-
importReactfrom'react'
197
-
import { useQuery } from'@tanstack/react-query'
198
-
import { fetchTodos, typeTodo } from'./api'
199
-
200
-
function TodoList({ query }: { query:UseQueryResult<Todo[]> }) {
For a more complete example, see [suspense example on GitHub](https://github.com/TanStack/query/tree/main/examples/react/suspense).
227
-
228
-
For a Next.js streaming example, see [nextjs-suspense-streaming example on GitHub](https://github.com/TanStack/query/tree/main/examples/react/nextjs-suspense-streaming).
Copy file name to clipboardExpand all lines: docs/framework/react/reference/useInfiniteQuery.md
-8Lines changed: 0 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,6 @@ const {
11
11
hasPreviousPage,
12
12
isFetchingNextPage,
13
13
isFetchingPreviousPage,
14
-
promise,
15
14
...result
16
15
} =useInfiniteQuery({
17
16
queryKey,
@@ -86,11 +85,4 @@ The returned properties for `useInfiniteQuery` are identical to the [`useQuery`
86
85
- Is the same as `isFetching && !isPending && !isFetchingNextPage && !isFetchingPreviousPage`
87
86
-`isRefetchError: boolean`
88
87
- Will be `true` if the query failed while refetching a page.
89
-
-`promise: Promise<TData>`
90
-
- A stable promise that resolves to the query result.
91
-
[//]: #'ReactUse'
92
-
- This can be used with `React.use()` to fetch data
93
-
[//]: #'ReactUse'
94
-
- Requires the `experimental_prefetchInRender` feature flag to be enabled on the `QueryClient`.
95
-
96
88
Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default refetch behaviour, resulting in outdated data. Make sure to call these functions only in response to user actions, or add conditions like `hasNextPage && !isFetching`.
0 commit comments