Rooms.tsx 1.01 KB
import React, { useContext, useEffect, useState } from 'react';
import { RouteComponentProps } from 'react-router';
import { Footer } from '../components/common/Footer';
import { MessageResponse, MessageType } from '../components/common/types';
import { Room } from '../components/rooms/types';
import SocketContext from '../contexts/SocketContext';

export const Rooms: React.FC<RouteComponentProps> = ({ history }) => {
  const socket = useContext(SocketContext);
  const [ rooms, setRooms ] = useState<Room[]>([]);

  const refreshRooms = () => {
    socket.emit(MessageType.ROOM_LIST_REQUEST, (response: MessageResponse<Room[]>) => {
      if (response.ok) {
        setRooms(response.result!);
      } else {
        // TODO: 에러 핸들링
        console.log("방 목록을 수신하지 못함");
      }
    });
  }

  useEffect(refreshRooms, []);

  return (
    <div>
      <header>header header</header>
      <div className='flex items-center'>
        <div>room test</div>
      </div>
      <Footer />
    </div>
  )
}