Overnap

createRooms 프로토콜에 맞게 수정

import React, { useCallback, useContext, useState } from 'react';
import { useHistory, useLocation } from 'react-router-dom';
import SocketContext from '../../contexts/SocketContext';
import { MessageResponse, MessageType, RawMessage } from '../common/types';
import { RoomData } from '../room/types';
import { Room } from './types';
interface CreateLocation {
state: { username: string }
}
export const Create: React.FC = () => {
const history = useHistory();
const socket = useContext(SocketContext);
const [ roomName, setRoomName ] = useState('');
const location: CreateLocation = useLocation();
const createRooms = useCallback(() => {
const rawMessage: RawMessage = {
type: MessageType.ROOM_LIST_CREATE,
message: { name: roomName }
}
socket.emit('msg', rawMessage, (response: MessageResponse<Room[]>) => {
socket.emit('msg', rawMessage, (response: MessageResponse<RoomData>) => {
if (response.ok) {
// HOW?
history.push({
pathname: '/' + response.result!.uuid,
state: {
username: location.state.username,
roomData: response.result!
}
});
} else {
console.log('방 생성 오류');
}
});
}, [roomName]);
......