Overnap

login 함수 프로토콜 규격 맞추고 useCallback으로 변경

import React, { useContext, useState } from 'react';
import React, { useCallback, useContext, useState } from 'react';
import { useHistory } from 'react-router';
import { Main } from '../components/common/Main';
import { MessageResponse, MessageType } from '../components/common/types';
......@@ -9,15 +9,17 @@ export const Login: React.FC = () => {
const socket = useContext(SocketContext);
const [ username, setUsername ] = useState("");
const login = () => {
socket.emit(MessageType.LOGIN, username, (response : MessageResponse<null>) => {
const login = useCallback(() => {
console.log("emitted.");
socket.emit('msg', {type: MessageType.LOGIN, message: {username}}, (response : MessageResponse<undefined>) => {
console.log("responsed.");
if (response.ok) {
history.push('/rooms');
} else {
console.error('login error!'); // TODO: 팝업 에러?
}
});
}
}, []);
return (
<Main>
......