Showing
1 changed file
with
6 additions
and
4 deletions
1 | -import React, { useContext, useState } from 'react'; | 1 | +import React, { useCallback, useContext, useState } from 'react'; |
2 | import { useHistory } from 'react-router'; | 2 | import { useHistory } from 'react-router'; |
3 | import { Main } from '../components/common/Main'; | 3 | import { Main } from '../components/common/Main'; |
4 | import { MessageResponse, MessageType } from '../components/common/types'; | 4 | import { MessageResponse, MessageType } from '../components/common/types'; |
... | @@ -9,15 +9,17 @@ export const Login: React.FC = () => { | ... | @@ -9,15 +9,17 @@ export const Login: React.FC = () => { |
9 | const socket = useContext(SocketContext); | 9 | const socket = useContext(SocketContext); |
10 | const [ username, setUsername ] = useState(""); | 10 | const [ username, setUsername ] = useState(""); |
11 | 11 | ||
12 | - const login = () => { | 12 | + const login = useCallback(() => { |
13 | - socket.emit(MessageType.LOGIN, username, (response : MessageResponse<null>) => { | 13 | + console.log("emitted."); |
14 | + socket.emit('msg', {type: MessageType.LOGIN, message: {username}}, (response : MessageResponse<undefined>) => { | ||
15 | + console.log("responsed."); | ||
14 | if (response.ok) { | 16 | if (response.ok) { |
15 | history.push('/rooms'); | 17 | history.push('/rooms'); |
16 | } else { | 18 | } else { |
17 | console.error('login error!'); // TODO: 팝업 에러? | 19 | console.error('login error!'); // TODO: 팝업 에러? |
18 | } | 20 | } |
19 | }); | 21 | }); |
20 | - } | 22 | + }, []); |
21 | 23 | ||
22 | return ( | 24 | return ( |
23 | <Main> | 25 | <Main> | ... | ... |
-
Please register or login to post a comment