-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
542695f
commit 4f6b316
Showing
1 changed file
with
24 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
--- | ||
"@apollo/client": minor | ||
--- | ||
|
||
Introduces a new `useLoadableQuery` hook. This hook works similarly to `useBackgroundQuery` in that it returns a `queryRef` that can be used to suspend a component via the `useReadQuery` hook. It provides a more ergonomic way to load the query during a user interaction (for example when wanting to preload some data) that would otherwise be clunky with `useBackgroundQuery`. | ||
|
||
```tsx | ||
function App() { | ||
const [queryRef, loadQuery, { refetch, fetchMore }] = useLoadableQuery(query, options) | ||
|
||
return ( | ||
<> | ||
<button onClick={() => loadQuery(variables)>Load query</button> | ||
{queryRef && <Child queryRef={queryRef} />} | ||
</> | ||
); | ||
} | ||
|
||
function Child({ queryRef }) { | ||
const { data } = useReadQuery(queryRef) | ||
|
||
// ... | ||
} | ||
``` |