Skip to content

Commit 33d43f7

Browse files
committed
docs: streamedQuery
1 parent 1361976 commit 33d43f7

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

docs/config.json

+4
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,10 @@
605605
"label": "QueriesObserver",
606606
"to": "reference/QueriesObserver"
607607
},
608+
{
609+
"label": "streamedQuery",
610+
"to": "reference/streamedQuery"
611+
},
608612
{
609613
"label": "focusManager",
610614
"to": "reference/focusManager"

docs/reference/QueryObserver.md

-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ id: QueryObserver
33
title: QueryObserver
44
---
55

6-
## `QueryObserver`
7-
86
The `QueryObserver` can be used to observe and switch between queries.
97

108
```tsx

docs/reference/streamedQuery.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
id: streamedQuery
3+
title: streamedQuery
4+
---
5+
6+
`streamedQuery` is a helper function to create a query function that streams data from an [AsyncIterable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncIterator). Data will be an Array of all the chunks received. The query will be in a `pending` state until the first chunk of data is received, but will go to `success` after that. The query will stay in fetchStatus `fetching` until the stream ends.
7+
8+
```tsx
9+
const query = queryOptions({
10+
queryKey: ['data'],
11+
queryFn: streamedQuery({
12+
queryFn: fetchDataInChunks,
13+
}),
14+
})
15+
```
16+
17+
**Options**
18+
19+
- `queryFn: (context: QueryFunctionContext) => Promise<AsyncIterable<TData>>`
20+
- **Required**
21+
- The function that returns a Promise of an AsyncIterable of data to stream in.
22+
- Receives a [QueryFunctionContext](../guides/query-functions.md#queryfunctioncontext)
23+
- `refetchMode?: 'append' | 'reset'`
24+
- optional
25+
- when set to `'reset'`, the query will erase all data and go back into `pending` state when a refetch occurs.
26+
- when set ot `'append'`, data will be appended on a refetch.
27+
- defaults to `'reset'`

0 commit comments

Comments
 (0)