Eric Whale

Setup chatroom page chatting room functionality

import axios from "axios";
import { useState, useEffect } from "react";
// components
import Bottombar from "./components/Bottombar";
import Topbar from "./components/Topbar";
import ChatroomBox from "./components/ChatroomBox";
function App() {
const [chats, setChats] = useState(null);
useEffect(() => {
axios.get("/api/chat").then((response) => {
setChats(response.data);
});
}, []);
return (
<div>
<Topbar />
......@@ -17,10 +27,13 @@ function App() {
<br />
<div>
<ChatroomBox />
<ChatroomBox />
<ChatroomBox />
<ChatroomBox />
{Array.isArray(chats) ? (
chats.map((chat, i) => {
return <ChatroomBox key={i} chat={chat} />;
})
) : (
<h2>No chatting room!</h2>
)}
</div>
<Bottombar />
</div>
......
......@@ -5,7 +5,7 @@ function UserBox({ user }) {
<div className="userBox">
<h1>{user.username}</h1>
<p>user info</p>
<div>chat!</div>
<div>chat!(chatting functionality)</div>
</div>
);
}
......