スキル一覧に戻る
narehart

hooks

by narehart

0🍴 0📅 2026年1月8日
GitHubで見るManusで実行

SKILL.md


name: hooks description: Create React hooks that bridge ECS and Zustand with React

React Hooks

Write custom hooks in src/hooks/ that bridge ECS/Zustand with React components.

Requirements

  • File naming: use*.ts (e.g., useMenuContext.ts)
  • One hook per file - enforced by ESLint
  • Named export matching filename

Pattern

import { useCallback, useMemo } from 'react';
import { useEntities } from 'miniplex-react';

import { world } from '../ecs/world';
import { useInventoryStore } from '../stores/inventoryStore';

interface UseHookNameProps {
  entityId: string;
}

interface UseHookNameReturn {
  data: SomeType;
  actions: {
    doSomething: () => void;
  };
}

export function useHookName(props: UseHookNameProps): UseHookNameReturn {
  const { entityId } = props;

  // ECS subscription
  const { entities } = useEntities(world.with('componentName'));

  // Zustand state
  const selectedId = useInventoryStore((state) => state.selectedItemId);

  // Derived data
  const data = useMemo(() => {
    return entities.find((e) => e.id === entityId);
  }, [entities, entityId]);

  // Actions
  const doSomething = useCallback(() => {
    // Call ECS system or Zustand action
  }, []);

  return {
    data,
    actions: { doSomething },
  };
}

Rules

  1. One hook per file - File name matches hook name
  2. Props interface - Use props object for multiple parameters
  3. Return interface - Define return type for complex returns
  4. Memoize appropriately - Use useMemo/useCallback for derived data and callbacks
  5. Bridge only - Hooks connect data sources to React, don't implement business logic

Hook Categories

ECS Bridge Hooks

Subscribe to ECS entities via miniplex-react:

import { useEntities } from 'miniplex-react';
const { entities } = useEntities(world.with('item'));

Zustand Bridge Hooks

Select state from Zustand stores:

const value = useInventoryStore((state) => state.value);
const action = useInventoryStore((state) => state.action);

Combined Hooks

Combine ECS queries with Zustand state for UI:

export function useMenuContext(): MenuContext {
  const { entities } = useEntities(world.with('item'));
  const selectedId = useInventoryStore((state) => state.selectedItemId);
  // Combine and return
}

Examples

Good hooks:

  • useECSInventory - subscribes to inventory entities
  • useMenuContext - combines ECS + Zustand for menu rendering
  • useGamepad - handles gamepad input events
  • useScale - manages UI scaling state

Bad (belong elsewhere):

  • useMoveItem - should be ECS system, not hook
  • useCalculateWeight - should be util, not hook

スコア

総合スコア

50/100

リポジトリの品質指標に基づく評価

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

0/10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

3ヶ月以内に更新がある

0/10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

0/5

レビュー

💬

レビュー機能は近日公開予定です