import ReactDOM from 'react-dom/client' import { QueryClient, QueryClientProvider, useQuery, } from '@tanstack/react-query' import { ReactQueryDevtools } from '@tanstack/react-query-devtools' import './style.css' import { useState } from 'react' import { chatQueryOptions } from './chat' import { Message } from './message' const queryClient = new QueryClient() export default function App() { return ( ) } function ChatMessage({ question }: { question: string }) { const { error, data = [], isFetching } = useQuery(chatQueryOptions(question)) if (error) return 'An error has occurred: ' + error.message return (
) } function Example() { const [questions, setQuestions] = useState>([]) const [currentQuestion, setCurrentQuestion] = useState('') const submitMessage = () => { setQuestions([...questions, currentQuestion]) setCurrentQuestion('') } return (

TanStack Chat Example

{questions.map((question) => ( ))}
setCurrentQuestion(e.target.value)} onKeyDown={(e) => { if (e.key === 'Enter') { submitMessage() } }} placeholder="Type your message..." />
) } const rootElement = document.getElementById('root') as HTMLElement ReactDOM.createRoot(rootElement).render()