---
name: zustand-entities
description: Use Zustand as a simple state store for entity management (not a true ECS).
---

# 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

- Not a true ECS, but simple and effective for many cases
- Store entities in an array with `create()`
- Use `getState()` in systems for non-reactive access (no re-renders)
- Use `useStore(selector)` in components for reactive updates
- Memoize entity components to prevent unnecessary re-renders
- Re-renders happen when entities are added/removed from the array

## Usage

```tsx
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

- Simple to understand and implement
- No automatic querying - must manually specify which entities to iterate
- Good for smaller games or prototypes

---

This skill is part of [verekia](https://x.com/verekia)'s [**r3f-gamedev**](https://github.com/verekia/r3f-gamedev).


---
Source attribution: verekia
Original project: https://github.com/verekia/r3f-gamedev/blob/1fec20bc549fb944374084b1a8c33b8ca5a927ef/skills/zustand-entities/SKILL.md
License: MIT
License information: https://opensource.org/license/mit
Original upstream instructions; downloaded from Mega AI Hub.

## Upstream license notice

MIT License

Copyright (c) 2026 Verekia

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.



# Mega AI Hub resource metadata

Creator / publisher: verekia
Original project: https://github.com/verekia/r3f-gamedev/blob/1fec20bc549fb944374084b1a8c33b8ca5a927ef/skills/zustand-entities/SKILL.md
Attribution basis: Source repository record

Fields of work: Development & Engineering, Product Management
Roles: Frontend Developer, Game Developer, Product Manager
Specialties: Backend, Cross Platform, Frontend
Tools: Zustand
Country applicability: Country not specified
Classification basis: Source catalog labels
Instruction SHA-256: dd1f2186a99eec00e1d9c0823b5ba435236f5d30f0c7d2cdc3d6c648b6445889
