refactor: simplify example app by moving renderBoard call into useGame
- Remove useMounted and manual renderBoard call from example App - Call renderBoard from useGame useEffect on initialization - Follow vim-maze pattern for cleaner example app
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { useState } from "react";
|
||||
import { useState, useEffect } from "react";
|
||||
import type { GameManager, GameOptions, KeyLogEntry } from "../types";
|
||||
import { useBoard } from "../useBoard";
|
||||
import { useCursor } from "../useCursor";
|
||||
@@ -21,6 +21,11 @@ export function useGame(
|
||||
boardManager.renderBoard(cursorManager.position());
|
||||
};
|
||||
|
||||
// Initial render on mount
|
||||
useEffect(() => {
|
||||
renderBoardWrapped();
|
||||
}, []);
|
||||
|
||||
const gameManager: GameManager = {
|
||||
containerRef: boardManager.containerRef,
|
||||
renderBoard: renderBoardWrapped,
|
||||
|
||||
Reference in New Issue
Block a user