Zustand entities

From verekia/r3f-gamedev · View interactive version

Zustand entities is an AI agent skill from the GitHub repository verekia/r3f-gamedev. Use Zustand as a simple state store for entity management (not a true ECS).

How to use this skill

Skill file

Zustand Entities

Use Zustand as a simple state store for entity management.

Technique

Store entities in a Zustand store array. Systems read from the store directly (non-reactively) in useFrame, while React components subscribe to the store for re-rendering when entities are added or removed.

Key Concepts

Usage

const useWorldStore = create(() => ({
  characters: [] as CharacterEntity[],
}))

// In systems (non-reactive)
useFrame(() => {
  for (const char of useWorldStore.getState().characters) {
    char.position.x += 0.01
  }
})

// In React (reactive)
const characters = useWorldStore(s => s.characters)
return characters.map(c => <Character key={c.id} entity={c} />)

Trade-offs


This skill is part of verekia's **r3f-gamedev**.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.