no useCallbacks or useMemos
This commit is contained in:
@@ -88,6 +88,7 @@ import { MazeRenderer } from './MazeRenderer';
|
||||
- **Explicit returns**: Always return objects from hooks
|
||||
- **Destructuring**: Use object destructuring for parameters and returns
|
||||
- **Arrow functions**: Prefer arrow functions for consistency
|
||||
- **No useCallback/useMemo**: React 19 optimization makes these hooks unnecessary
|
||||
|
||||
### Error Handling
|
||||
- **Early returns**: Guard clauses at function start
|
||||
@@ -176,6 +177,7 @@ export function useGame(options: GameOptions, platformHook?: unknown): GameManag
|
||||
- Break existing patterns without reason
|
||||
- Write overly complex implementations
|
||||
- Add unnecessary features
|
||||
- Use `useCallback` or `useMemo` anywhere in the codebase
|
||||
|
||||
### Always DO
|
||||
- Follow existing code patterns exactly
|
||||
@@ -183,4 +185,5 @@ export function useGame(options: GameOptions, platformHook?: unknown): GameManag
|
||||
- Maintain type safety
|
||||
- Keep implementations simple and focused
|
||||
- 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
|
||||
- ✅ **useKeyBindings implementation** - Complete
|
||||
- ✅ **useCursor implementation** - Complete
|
||||
- 🔄 **useBoard implementation** - In progress
|
||||
- 🔄 **useGame implementation** - In progress
|
||||
- ✅ **useBoard implementation** - Complete
|
||||
- ✅ **useGame implementation** - Complete
|
||||
- ✅ **React 19 optimization** - No useCallback/useMemo usage
|
||||
- ⏳ **Platform integration** - Pending
|
||||
- ⏳ **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 gameStatusManager = useGameStatus();
|
||||
|
||||
const { gameStatus, startGame, togglePause, quitGame, setGameStatus } = gameStatusManager;
|
||||
const { gameStatus, startGame, togglePause, quitGame, setGameStatus } = gameStatusManager;
|
||||
|
||||
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';
|
||||
|
||||
export function useGameStatus(board?: BoardManager, setHeroPos?: (pos: Coord) => void) {
|
||||
const [gameStatus, setGameStatus] = useState<GameStatus>('waiting');
|
||||
|
||||
const startGame = useCallback(() => {
|
||||
function startGame() {
|
||||
if (board && setHeroPos) {
|
||||
const m = board.mazeRef.current;
|
||||
if (!m.length) return;
|
||||
@@ -17,7 +17,7 @@ export function useGameStatus(board?: BoardManager, setHeroPos?: (pos: Coord) =>
|
||||
}
|
||||
}
|
||||
setGameStatus('started');
|
||||
}, [board, setHeroPos]);
|
||||
}
|
||||
|
||||
function togglePause(pause?: boolean) {
|
||||
if (typeof pause === 'boolean') {
|
||||
|
||||
Reference in New Issue
Block a user