ecspresso
    Preparing search index...

    Function createEcsHooks

    • Creates typed hooks bound to a specific world config.

      Call once at module scope with your world type, then use the returned hooks in components anywhere under the EcsContext.Provider.

      Type Parameters

      • W extends default<any, string, string, string, string>

      Returns {
          useEcs: () => W;
          useEvent: <E extends string>(
              type: E,
              callback: (data: Events[E]) => void,
          ) => void;
          useResource: <K extends string>(key: K) => Resources[K];
      }

      • useEcs: () => W
      • useEvent: <E extends string>(type: E, callback: (data: Events[E]) => void) => void
      • useResource: <K extends string>(key: K) => Resources[K]
      const ecs = ECSpresso.create()
      .withResourceTypes<{ score: number; health: number }>()
      .withEventTypes<{ enemyKilled: { id: number } }>()
      .build();

      type ECS = typeof ecs;
      const { useResource, useEvent, useEcs } = createEcsHooks<ECS>();