Skip to content

Commit

Permalink
fix: useCreateRoom에서 방 생성 이벤트 및 에러 처리 로직 업데이트
Browse files Browse the repository at this point in the history
  • Loading branch information
zizonyoungjun committed Nov 19, 2024
1 parent ccd30d1 commit d06b6f9
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions packages/frontend/src/hooks/useCreateRoom.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import { useNavigate } from 'react-router-dom';
import { useAuthStore } from '@/states/store/authStore';
import { useRoomStore } from '@/states/store/roomStore';
import { useSocketStore } from '@/states/store/socketStore';

export default function useCreateRoom() {
const navigate = useNavigate();
const userId = useAuthStore((state) => state.userId);
Expand All @@ -13,13 +8,19 @@ export default function useCreateRoom() {
if (!userId || !socket) return;

socket.emit('create_room', { usid: userId });

socket.on('create_room_success', (data) => {
setRoomData(data.gsid, data.isHost);
navigate(`/game/${data.gsid}`);
});

socket.on('error', (data) => {
alert(`방 생성에 실패했습니다: ${data.errorMessage}`);
});

return () => {
socket.off('create_room_success');
socket.off('error');
};
}

Expand Down

0 comments on commit d06b6f9

Please sign in to comment.