Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

README.md

14 lines875 Bytes

1# TanStack Solid Query Chat Example
2​
3A chat UI that streams the answer into the query cache with `streamedQuery`.
4​
5## How it works
6​
7- `src/services/messages/queries.ts` defines `messagesQueries.detail(id, question)` with `queryOptions`. Its `queryFn` is `streamedQuery` (imported as `experimental_streamedQuery`), which appends each chunk from `streamFn` to `data` as it arrives, and `staleTime: Infinity` keeps a finished answer from being refetched.
8- `src/services/messages/api.ts` returns an async iterable that yields a canned answer word by word with random delays and stops when the query's `signal` is aborted.
9- `src/index.tsx` renders a `ChatMessage` per question, which reads the streamed words from `useQuery` and joins them. `isFetching` stays `true` until the stream ends, which shows the "..." indicator.
10​
11To run this example:
12​
13- `npm install`
14- `npm run dev`