From 6179021ce75be232e3aee99cdddc5d4403c68b6d Mon Sep 17 00:00:00 2001 From: Vishesh 'ironeagle' Bangotra Date: Fri, 28 Nov 2025 14:08:10 +0530 Subject: [PATCH] useEffect for managing match udpate --- src/tictactoe/TicTacToe.tsx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/tictactoe/TicTacToe.tsx b/src/tictactoe/TicTacToe.tsx index f101958..1981370 100644 --- a/src/tictactoe/TicTacToe.tsx +++ b/src/tictactoe/TicTacToe.tsx @@ -4,7 +4,6 @@ import Board from "./Board"; export default function TicTacToe() { const [username, setUsername] = useState(""); - const [board, setBoard] = useState([ ["", "", ""], ["", "", ""], @@ -21,6 +20,18 @@ export default function TicTacToe() { matchId, } = useNakama(); + useEffect(() => { + onMatchData((msg) => { + console.log("[Match Data]", msg); + + if (msg.opCode === 2) { + setBoard(msg.data.board); + setTurn(msg.data.turn); + setWinner(msg.data.winner || null); + } + }); + }, [onMatchData]); + // ------------------------------------------ // CONNECT // ------------------------------------------