Skip to content

Commit

Permalink
Add a changeset
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Nov 10, 2023
1 parent 542695f commit 4f6b316
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .changeset/thirty-ties-arrive.md
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)

// ...
}
```

0 comments on commit 4f6b316

Please sign in to comment.