Skip to content

Commit

Permalink
Split intro to toPromise into 2 paragraphs
Browse files Browse the repository at this point in the history
Co-authored-by: Alessia Bellisario <[email protected]>
  • Loading branch information
jerelmiller and alessbell authored Jan 26, 2024
1 parent 08c845d commit 4176bfe
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion docs/source/data/suspense.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,11 @@ The `preloadQuery` function only works with client-side routing. The `queryRef`

#### Preventing route transitions until the query is loaded

By default, `preloadQuery` works similar to a [deferred loader](https://reactrouter.com/en/main/guides/deferred) in that routes will transition immediately and suspend with `useReadQuery` until the query is loaded. You may instead want to prevent the route from transitioning until the data is fully loaded. Use the `toPromise` method on the `queryRef` to get a promise that resolves when the query is loaded. This promise resolves with the `queryRef` itself, making it easy to use with hooks such as `useLoaderData`.
By default, `preloadQuery` works similar to a [deferred loader](https://reactrouter.com/en/main/guides/deferred): the route will transition immediately and the incoming page that's attempting to read the data via `useReadQuery` will suspend until the network request finishes.

But what if we want to prevent the route from transitioning until the data is fully loaded? The `toPromise` method on a `queryRef` provides access to a promise that resolves when the network request has completed. This promise resolves with the `queryRef` itself, making it easy to use with hooks such as `useLoaderData`.

Here's an example:

```ts
export async function loader() {
Expand Down

0 comments on commit 4176bfe

Please sign in to comment.