no useCallbacks or useMemos
This commit is contained in:
@@ -88,6 +88,7 @@ import { MazeRenderer } from './MazeRenderer';
|
|||||||
- **Explicit returns**: Always return objects from hooks
|
- **Explicit returns**: Always return objects from hooks
|
||||||
- **Destructuring**: Use object destructuring for parameters and returns
|
- **Destructuring**: Use object destructuring for parameters and returns
|
||||||
- **Arrow functions**: Prefer arrow functions for consistency
|
- **Arrow functions**: Prefer arrow functions for consistency
|
||||||
|
- **No useCallback/useMemo**: React 19 optimization makes these hooks unnecessary
|
||||||
|
|
||||||
### Error Handling
|
### Error Handling
|
||||||
- **Early returns**: Guard clauses at function start
|
- **Early returns**: Guard clauses at function start
|
||||||
@@ -176,6 +177,7 @@ export function useGame(options: GameOptions, platformHook?: unknown): GameManag
|
|||||||
- Break existing patterns without reason
|
- Break existing patterns without reason
|
||||||
- Write overly complex implementations
|
- Write overly complex implementations
|
||||||
- Add unnecessary features
|
- Add unnecessary features
|
||||||
|
- Use `useCallback` or `useMemo` anywhere in the codebase
|
||||||
|
|
||||||
### Always DO
|
### Always DO
|
||||||
- Follow existing code patterns exactly
|
- Follow existing code patterns exactly
|
||||||
@@ -184,3 +186,4 @@ export function useGame(options: GameOptions, platformHook?: unknown): GameManag
|
|||||||
- Keep implementations simple and focused
|
- Keep implementations simple and focused
|
||||||
- Update documentation proactively
|
- Update documentation proactively
|
||||||
- Test builds after changes
|
- Test builds after changes
|
||||||
|
- Use plain functions instead of `useCallback`/`useMemo` (React 19 optimization)
|
||||||
+3
-2
@@ -262,8 +262,9 @@ The unified API is designed to accommodate:
|
|||||||
- ✅ **useGameStatus implementation** - Complete
|
- ✅ **useGameStatus implementation** - Complete
|
||||||
- ✅ **useKeyBindings implementation** - Complete
|
- ✅ **useKeyBindings implementation** - Complete
|
||||||
- ✅ **useCursor implementation** - Complete
|
- ✅ **useCursor implementation** - Complete
|
||||||
- 🔄 **useBoard implementation** - In progress
|
- ✅ **useBoard implementation** - Complete
|
||||||
- 🔄 **useGame implementation** - In progress
|
- ✅ **useGame implementation** - Complete
|
||||||
|
- ✅ **React 19 optimization** - No useCallback/useMemo usage
|
||||||
- ⏳ **Platform integration** - Pending
|
- ⏳ **Platform integration** - Pending
|
||||||
- ⏳ **Advanced features** - Pending (scoring, animations, etc.)
|
- ⏳ **Advanced features** - Pending (scoring, animations, etc.)
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -10,7 +10,7 @@ export function useGame(options: GameOptions, platformHook?: unknown): GameManag
|
|||||||
const { containerRef, renderBoard } = board;
|
const { containerRef, renderBoard } = board;
|
||||||
const gameStatusManager = useGameStatus();
|
const gameStatusManager = useGameStatus();
|
||||||
|
|
||||||
const { gameStatus, startGame, togglePause, quitGame, setGameStatus } = gameStatusManager;
|
const { gameStatus, startGame, togglePause, quitGame, setGameStatus } = gameStatusManager;
|
||||||
|
|
||||||
const cursor = useCursor(board, gameStatus);
|
const cursor = useCursor(board, gameStatus);
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import { useState, useCallback } from 'react';
|
import { useState } from 'react';
|
||||||
import type { GameStatus, BoardManager, Coord } from '../types';
|
import type { GameStatus, BoardManager, Coord } from '../types';
|
||||||
|
|
||||||
export function useGameStatus(board?: BoardManager, setHeroPos?: (pos: Coord) => void) {
|
export function useGameStatus(board?: BoardManager, setHeroPos?: (pos: Coord) => void) {
|
||||||
const [gameStatus, setGameStatus] = useState<GameStatus>('waiting');
|
const [gameStatus, setGameStatus] = useState<GameStatus>('waiting');
|
||||||
|
|
||||||
const startGame = useCallback(() => {
|
function startGame() {
|
||||||
if (board && setHeroPos) {
|
if (board && setHeroPos) {
|
||||||
const m = board.mazeRef.current;
|
const m = board.mazeRef.current;
|
||||||
if (!m.length) return;
|
if (!m.length) return;
|
||||||
@@ -17,7 +17,7 @@ export function useGameStatus(board?: BoardManager, setHeroPos?: (pos: Coord) =>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
setGameStatus('started');
|
setGameStatus('started');
|
||||||
}, [board, setHeroPos]);
|
}
|
||||||
|
|
||||||
function togglePause(pause?: boolean) {
|
function togglePause(pause?: boolean) {
|
||||||
if (typeof pause === 'boolean') {
|
if (typeof pause === 'boolean') {
|
||||||
|
|||||||
Reference in New Issue
Block a user