Skip to content

Commit aa7b6a2

Browse files
authored
move createQueryPreloader example (#11613)
1 parent 19f2efc commit aa7b6a2

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

CHANGELOG.md

+19-19
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,25 @@
127127

128128
- [#11412](https://github.com/apollographql/apollo-client/pull/11412) [`58db5c3`](https://github.com/apollographql/apollo-client/commit/58db5c3295b88162f91019f0898f6baa4b9cced6) Thanks [@jerelmiller](https://github.com/jerelmiller)! - Add the ability to start preloading a query outside React to begin fetching as early as possible. Call `createQueryPreloader` to create a `preloadQuery` function which can be called to start fetching a query. This returns a `queryRef` which is passed to `useReadQuery` and suspended until the query is done fetching.
129129

130+
```tsx
131+
const preloadQuery = createQueryPreloader(client);
132+
const queryRef = preloadQuery(QUERY, { variables, ...otherOptions });
133+
134+
function App() {
135+
return {
136+
<Suspense fallback={<div>Loading</div>}>
137+
<MyQuery />
138+
</Suspense>
139+
}
140+
}
141+
142+
function MyQuery() {
143+
const { data } = useReadQuery(queryRef);
144+
145+
// do something with data
146+
}
147+
```
148+
130149
#### Testing utility improvements
131150

132151
- [#11178](https://github.com/apollographql/apollo-client/pull/11178) [`4d64a6f`](https://github.com/apollographql/apollo-client/commit/4d64a6fa2ad5abe6f7f172c164f5e1fc2cb89829) Thanks [@sebakerckhof](https://github.com/sebakerckhof)! - Support re-using of mocks in the MockedProvider
@@ -193,25 +212,6 @@
193212

194213
The `IGNORE` sentinel can be destructured from the second parameter in the callback function signature passed to `optimisticResponse`.
195214

196-
```tsx
197-
const preloadQuery = createQueryPreloader(client);
198-
const queryRef = preloadQuery(QUERY, { variables, ...otherOptions });
199-
200-
function App() {
201-
return {
202-
<Suspense fallback={<div>Loading</div>}>
203-
<MyQuery />
204-
</Suspense>
205-
}
206-
}
207-
208-
function MyQuery() {
209-
const { data } = useReadQuery(queryRef);
210-
211-
// do something with data
212-
}
213-
```
214-
215215
#### Network adapters for multipart subscriptions usage with Relay and urql
216216

217217
- [#11301](https://github.com/apollographql/apollo-client/pull/11301) [`46ab032`](https://github.com/apollographql/apollo-client/commit/46ab032af83a01f184bfcce5edba4b55dbb2962a) Thanks [@alessbell](https://github.com/alessbell)! - Add multipart subscription network adapters for Relay and urql

0 commit comments

Comments
 (0)