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-10 03:56:27 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
da329fcd6d52429a2b65378526359d21d01721c3
da329fcd
1 parent
cac7aeb8
Word 컴포넌트 추가
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
0 deletions
web/src/components/room/Word.tsx
web/src/components/room/Word.tsx
0 → 100644
View file @
da329fc
import React, { useCallback, useContext } from 'react';
import { IndexType } from 'typescript';
import SocketContext from '../../contexts/SocketContext';
import { MessageResponse, MessageType, RawMessage } from '../common/types';
interface WordProps {
index: number;
word: string;
setWordChosen: (value: React.SetStateAction<string>) => void;
setWords: (value: React.SetStateAction<string[]>) => void;
}
export const Word: React.FC<WordProps> = (props) => {
const socket = useContext(SocketContext);
const handleChoose = useCallback(() => {
const rawMessage: RawMessage = {
type: MessageType.GAME_CHOOSE,
message: { word: props.word }
};
socket.emit('msg', rawMessage, (response: MessageResponse<undefined>) => {
if (response.ok) {
props.setWords([]);
props.setWordChosen(props.word);
}
});
}, [props.setWordChosen]);
return (
<button className={`bg-green-500 active:bg-green-600 fixed
text-white font-bold ${'mt-' + 40*(props.index+1)} mt-40
px-5 py-2 rounded shadow
outline-none focus:outline-none hover:shadow-md
ease-linear transition-all duration-100`}
type="button"
onClick={() => handleChoose()}>{props.word}</button>
);
}
Please
register
or
login
to post a comment