Skip to content

Commit

Permalink
feat: use router.push for redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
agrattan0820 committed Sep 24, 2023
1 parent e658d99 commit cd6ed14
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions apps/client/src/app/room/[code]/game/[gameId]/game.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { EventFrom, State } from "xstate";
import { useMachine } from "@xstate/react";
import { AnimatePresence } from "framer-motion";
import { useQuery } from "@tanstack/react-query";
import { redirect } from "next/navigation";
import { useRouter } from "next/navigation";

import {
GameInfo,
Expand Down Expand Up @@ -36,6 +36,8 @@ export default function Game({ gameInfo, session }: GameProps) {
// Socket for real-time communication
const socket = useContext(SocketContext);

const router = useRouter();

// Wait until the client mounts to avoid hydration errors
const [isMounted, setIsMounted] = useState(false);

Expand Down Expand Up @@ -138,9 +140,9 @@ export default function Game({ gameInfo, session }: GameProps) {
const handlePlayAnotherGame = useCallback(
(gameId: number) => {
send("NEXT");
redirect(`/room/${gameInfo.game.roomCode}/game/${gameId}`);
router.push(`/room/${gameInfo.game.roomCode}/game/${gameId}`);
},
[gameInfo.game.roomCode, send],
[gameInfo.game.roomCode, router, send],
);

// Send new state to server
Expand Down

0 comments on commit cd6ed14

Please sign in to comment.