examples/lit/chat
| Name | Last commit message | Last commit date |
|---|---|---|
| .. | ||
README.md
TanStack Lit Query Chat Example#
A chat UI that streams the answer into the query cache with streamedQuery.
How it works#
src/services/messages/queries.tsdefinesmessagesQueries.detail(id, question), aqueryOptionsfactory whosequeryFnisexperimental_streamedQuery(imported asstreamedQuery) withstaleTime: Infinity.src/services/messages/api.tsreturns an async iterable that yields the answer one word at a time with a random delay and stops when thesignalaborts.src/chat-message.tscallscreateQueryControllerwithmessagesQueries.detail(...).datagrows as chunks arrive and is joined into the answer, andisFetchingstaystrueuntil the stream ends.src/main.tssubclassesQueryClientProviderto set the sharedQueryClientand renders one<chat-message>per submitted question.
To run this example:
npm installnpm run dev