Skip to content

Installation

Phaser Hooks is a modern, lightweight state management library designed specifically for Phaser.js games. It provides React-inspired patterns (but without React) and state management approaches that make your game development more organized, maintainable, and scalable.

Phaser Hooks brings familiar React patterns to Phaser.js development, offering:

  • Local State Management - Component-level state with withLocalState
  • Global State Management - Cross-scene state sharing with withGlobalState
  • Event-Driven Architecture - Reactive state updates with automatic re-rendering
  • TypeScript Support - Full type safety and IntelliSense
  • Performance Optimized - Minimal overhead with smart update batching

Create a new Astro + Starlight project by running the following command in your terminal:

Terminal window
npm i phaser-hooks

If you are using a CDN, you can install Phaser Hooks with the following code:

<script src="https://unpkg.com/phaser-hooks/dist/phaser-hooks.umd.js"></script>

Then you can use the library in your code like this:

window.PhaserHooks.withLocalState(this, 'player', { hp: 100 });
// If you are using TypeScript with UMD, you can import the library from global like this:
declare const Phaser: typeof import('phaser');
declare const PhaserHooks: typeof import('phaser-hooks');

⚠️ Note: While UMD builds are available, we strongly recommend using TypeScript for better type safety, IntelliSense, and development experience. The TypeScript version provides better error detection and autocomplete features.