diff --git a/src/lib/bingosync.ts b/src/lib/bingosync.ts index 8b08f2a..a8d2545 100644 --- a/src/lib/bingosync.ts +++ b/src/lib/bingosync.ts @@ -350,7 +350,17 @@ export class Bingosync extends EventEmitter { if (json.type === "goal") { const index = parseInt(json.square.slot.slice(4), 10) - 1; - this.boardState.cells[index] = json.square; + + // Update the state in an immutable manner. + // This improves our interop with things like React. + const newBoardState = { + cells: this.boardState.cells.slice(0), + }; + newBoardState.cells[index] = { + ...newBoardState.cells[index], + ...json.square, + }; + this.boardState = newBoardState; this.emit("board-changed", this.boardState); } };