Open History to see the last commit
1# TanStack Preact 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- In `src/index.tsx`, each `ChatMessage` calls `useQuery(messagesQueries.detail(id, question))`. `data` grows as chunks arrive and is joined into the answer, and `isFetching` stays `true` until the stream ends.
10β
11To run this example:
12β
13- `npm install`
14- `npm run dev`