()
| 42 | } |
| 43 | |
| 44 | function Example() { |
| 45 | const [questions, setQuestions] = useState< |
| 46 | Array<{ id: string; question: string }> |
| 47 | >([]) |
| 48 | const [currentQuestion, setCurrentQuestion] = useState('') |
| 49 | |
| 50 | const submitMessage = () => { |
| 51 | setQuestions([ |
| 52 | ...questions, |
| 53 | { id: crypto.randomUUID(), question: currentQuestion }, |
| 54 | ]) |
| 55 | setCurrentQuestion('') |
| 56 | } |
| 57 | |
| 58 | return ( |
| 59 | <div className="flex flex-col h-screen max-w-3xl mx-auto p-4"> |
| 60 | <h1 className="text-3xl font-bold text-gray-800"> |
| 61 | TanStack Chat Example |
| 62 | </h1> |
| 63 | <div className="overflow-y-auto mb-4 space-y-4"> |
| 64 | {questions.map(({ id, question }) => ( |
| 65 | <ChatMessage key={id} id={id} question={question} /> |
| 66 | ))} |
| 67 | </div> |
| 68 | |
| 69 | <form |
| 70 | className="flex items-center space-x-2" |
| 71 | onSubmit={(e) => { |
| 72 | e.preventDefault() |
| 73 | submitMessage() |
| 74 | }} |
| 75 | > |
| 76 | <input |
| 77 | className="flex-1 p-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 focus:ring-offset-gray-100" |
| 78 | value={currentQuestion} |
| 79 | onChange={(e) => setCurrentQuestion(e.target.value)} |
| 80 | placeholder="Type your message..." |
| 81 | /> |
| 82 | <button |
| 83 | type="submit" |
| 84 | disabled={!currentQuestion.trim()} |
| 85 | className="flex items-center gap-2 bg-blue-600 hover:bg-blue-700 text-white font-semibold px-4 py-2 rounded-2xl shadow-md transition" |
| 86 | > |
| 87 | <span>Send</span> |
| 88 | <svg |
| 89 | xmlns="http://www.w3.org/2000/svg" |
| 90 | width="24" |
| 91 | height="24" |
| 92 | viewBox="0 0 24 24" |
| 93 | fill="none" |
| 94 | stroke="currentColor" |
| 95 | strokeWidth="2" |
| 96 | strokeLinecap="round" |
| 97 | strokeLinejoin="round" |
| 98 | > |
| 99 | <path d="M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z" /> |
| 100 | <path d="m21.854 2.147-10.94 10.939" /> |
| 101 | </svg> |
nothing calls this directly
no test coverage detected