Skip to content

Commit 9867c54

Browse files
committed
docs: deferring queries
1 parent a4c197d commit 9867c54

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
sidebar_position: 3
3+
---
4+
5+
# Deferring queries
6+
7+
Say you have a query that takes a long time to resolve. You want to put it in the loader, to co-locate it with the rest of your queries, but you don't want it to affect the loading state and postpone the initial load of the component. This is where `deferredQueries` comes in.
8+
9+
## Example
10+
11+
```typescript {3-7}
12+
const loader = createLoader({
13+
queries: () => [useImportantQuery()] as const,
14+
deferredQueries: () => [useSlowQuery()] as const,
15+
transform: (queries, deferred) => ({
16+
important: queries[0].data,
17+
slow: deferred[0].data,
18+
}),
19+
});
20+
```
21+
22+
Deferred queries are not automatically passed to the output of the loader, you have to use the `transform` argument (and it's second argument) to expose the queries for the consumers. The format of how you transform it is not important, but it is the only way to _get_ the deferred query result out of the loader.
23+
24+
Deferred queries
25+
26+
- Do not affect the loading state
27+
- Are only exposed through `transform`
28+
- Cause the component to rerender when fulfilled

0 commit comments

Comments
 (0)