Getting started
Install Zenty, create your first typed Zustand store and pick the right helper: createEntitiesStore for lists, createEntityStore for single objects.
Applies to zenty v1.1.0
Zenty is a small TypeScript library on top of Zustand. You describe your data with a type, and Zenty gives you a normal Zustand store with the CRUD actions and the loading, loaded and error state you would otherwise write by hand.
Install(link to this section)
Zustand and React are peer dependencies. Zenty works with Zustand 4.4+ and 5, and React 18 or 19.
npm install zenty zustandpnpm add zenty zustandyarn add zenty zustandYour first store(link to this section)
If your type has an id field, a store is one call. Everything is typed from Product: the actions only accept products, and IDs are typed as string.
import { createEntitiesStore } from 'zenty'
type Product = { id: string; name: string; price?: number }
export const useProducts = createEntitiesStore<Product>()Use it in a component(link to this section)
The result is a regular Zustand hook. Destructure what you need, or pass a selector like useProducts((s) => s.entities) to re-render only when that part changes.
'use client'
import { useProducts } from '@/stores/products'
export function ProductList() {
const { entities, loading, error, add, delete: remove } = useProducts()
if (loading) return <p>Loading…</p>
if (error) return <p role="alert">{error}</p>
return (
<>
<ul>
{entities.map((p) => (
<li key={p.id}>
{p.name} <button onClick={() => remove(p.id)}>Delete</button>
</li>
))}
</ul>
<button onClick={() => add({ id: crypto.randomUUID(), name: 'New product' })}>
Add product
</button>
</>
)
}Which store do I need?(link to this section)
- A list of things with IDs, like products, users or todos: createEntitiesStore.
- One object, like settings, the current user or a form draft: createEntityStore.
import { createEntityStore } from 'zenty'
type Settings = { theme: 'light' | 'dark'; notifications: { email: boolean; push: boolean } }
export const useSettings = createEntityStore<Settings>({ deepMerge: true })What Zenty doesn't do(link to this section)
Zenty doesn't fetch, cache or refetch data, and it has no selection or pagination state. If you need server caching and invalidation, TanStack Query is the better fit, and many apps use both. Store logic that isn't CRUD stays in hand-written Zustand stores, which live next to Zenty stores without any setup.
Next: the loading and error guide shows how async calls fit in.
Found a mistake? Open an issue.