zustand-entities

Use Zustand as a simple state store for entity management (not a true ECS).

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "zustand-entities" with this command: npx skills add verekia/r3f-gamedev/verekia-r3f-gamedev-zustand-entities

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

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's r3f-gamedev.

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

Coding

smooth-interpolation

No summary provided by upstream source.

Repository SourceNeeds Review
Coding

reactive-polling

No summary provided by upstream source.

Repository SourceNeeds Review
Coding

ui-useframe

No summary provided by upstream source.

Repository SourceNeeds Review
Coding

pushback

No summary provided by upstream source.

Repository SourceNeeds Review