Skip to content

Commit 121c702

Browse files
committed
Create basic client UI
1 parent 2cbec44 commit 121c702

1 file changed

Lines changed: 23 additions & 14 deletions

File tree

chat-app/client/src/App.jsx

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
1-
import { io } from "socket.io-client";
2-
import "./App.css";
1+
import { useState } from "react";
2+
import useSocket from "./hooks/useSocket";
33

4-
const App = () => {
5-
const socket = io("http://localhost:3000");
4+
export default function App() {
5+
const { messages, sendMessage } = useSocket("http://localhost:3000");
6+
const [input, setInput] = useState("");
67

7-
socket.on("connect", () => {
8-
console.log(socket.id);
9-
});
10-
11-
socket.on("message", (data) => console.log(data));
12-
13-
return <></>;
14-
};
15-
16-
export default App;
8+
const handleSend = () => {
9+
if (!input.trim()) return;
10+
sendMessage(input.trim());
11+
setInput("");
12+
};
13+
14+
return (
15+
<div>
16+
<ul>
17+
{messages.map((msg, i) => (
18+
<li key={i}>{msg.text}</li>
19+
))}
20+
</ul>
21+
<input value={input} onChange={(e) => setInput(e.target.value)} />
22+
<button onClick={handleSend}>Send</button>
23+
</div>
24+
);
25+
}

0 commit comments

Comments
 (0)