Toggle navigation
Toggle navigation
This project
Loading...
Sign in
강동현
/
nodejs-game
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Overnap
2021-06-06 00:59:49 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
aa80dd220e3c24881f3b5e2b2618ec201e67c653
aa80dd22
1 parent
34c44f47
login 함수 프로토콜 규격 맞추고 useCallback으로 변경
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
4 deletions
web/src/pages/Login.tsx
web/src/pages/Login.tsx
View file @
aa80dd2
import React, { useContext, useState } from 'react';
import React, { useC
allback, useC
ontext, 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>
...
...
Please
register
or
login
to post a comment