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

README.md

15 lines900 Bytes

1# TanStack Lit 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)`, a `queryOptions` factory whose `queryFn` is `experimental_streamedQuery` (imported as `streamedQuery`) with `staleTime: Infinity`.
8- `src/services/messages/api.ts` returns an async iterable that yields the answer one word at a time with a random delay and stops when the `signal` aborts.
9- `src/chat-message.ts` calls `createQueryController` with `messagesQueries.detail(...)`. `data` grows as chunks arrive and is joined into the answer, and `isFetching` stays `true` until the stream ends.
10- `src/main.ts` subclasses `QueryClientProvider` to set the shared `QueryClient` and renders one `<chat-message>` per submitted question.
11​
12To run this example:
13​
14- `npm install`
15- `npm run dev`