MCPcopy Create free account
hub / github.com/TanStack/query / Example

Function Example

examples/solid/chat/src/index.tsx:45–105  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

43}
44
45function Example() {
46 const [questions, setQuestions] = createSignal<
47 Array<{ id: string; question: string }>
48 >([])
49 const [currentQuestion, setCurrentQuestion] = createSignal('')
50
51 const submitMessage = () => {
52 setQuestions([
53 ...questions(),
54 { id: crypto.randomUUID(), question: currentQuestion() },
55 ])
56 setCurrentQuestion('')
57 }
58
59 return (
60 <div class="flex flex-col h-screen max-w-3xl mx-auto p-4">
61 <h1 class="text-3xl font-bold text-gray-800">TanStack Chat Example</h1>
62 <div class="overflow-y-auto mb-4 space-y-4">
63 <For each={questions()}>
64 {(item) => <ChatMessage id={item.id} question={item.question} />}
65 </For>
66 </div>
67
68 <form
69 class="flex items-center space-x-2"
70 onSubmit={(e) => {
71 e.preventDefault()
72 submitMessage()
73 }}
74 >
75 <input
76 class="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"
77 value={currentQuestion()}
78 onInput={(e) => setCurrentQuestion(e.currentTarget.value)}
79 placeholder="Type your message..."
80 />
81 <button
82 type="submit"
83 disabled={!currentQuestion().trim()}
84 class="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"
85 >
86 <span>Send</span>
87 <svg
88 xmlns="http://www.w3.org/2000/svg"
89 width="24"
90 height="24"
91 viewBox="0 0 24 24"
92 fill="none"
93 stroke="currentColor"
94 stroke-width="2"
95 stroke-linecap="round"
96 stroke-linejoin="round"
97 >
98 <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" />
99 <path d="m21.854 2.147-10.94 10.939" />
100 </svg>
101 </button>
102 </form>

Callers

nothing calls this directly

Calls 1

submitMessageFunction · 0.70

Tested by

no test coverage detected