Overnap

handleChatData 프로토콜에 맞게 수정

......@@ -11,12 +11,16 @@ export const Chat: React.FC = () => {
const messageEndRef = useRef<HTMLDivElement | null>(null);
useEffect(() => {
socket.on(MessageType.ROOM_CHAT, (data: ChatData) => {
setChatLines([...chatLines, data]);
});
const handleChatData = (message: RawMessage) => {
if (message.type === MessageType.ROOM_CHAT) {
setChatLines(oldChatLines => [...oldChatLines, message.message as ChatData]);
}
}
socket.on('msg', handleChatData);
return () => {
socket.off(MessageType.ROOM_CHAT);
socket.off('msg', handleChatData);
}
}, []);
......@@ -28,7 +32,7 @@ export const Chat: React.FC = () => {
const handleEnter = useCallback((e: React.KeyboardEvent) => {
if (e.key === 'Enter') {
setChatLines([...chatLines, { sender: 'me', message: input }]);
// setChatLines([...chatLines, { sender: 'me', message: input }]);
const rawMessage: RawMessage = {
type: MessageType.ROOM_CHAT,
......