Zustand-computed is a lightweight, TypeScript-friendly middleware designed for the Zustand state management library, enabling the creation of derived or 'computed' state based on the existing store state. The current stable version is 2.1.2, released in April 2026. The package maintains an active release cadence, with multiple bug fixes and minor features released within the last year, demonstrating ongoing development and support. Its primary differentiator is its simplicity and direct integration with Zustand's middleware pattern, providing a straightforward way to add calculated properties to a store without manual memoization or complex selectors. It focuses on functional transformations and offers options to optimize recomputation with `keys` or a `shouldRecompute` function, differentiating it from purely selector-based approaches by integrating computed values directly into the store's state tree.
npm install zustand-computedVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to define a Zustand store with computed state using `createComputed`, including TypeScript types, and basic state manipulation. It shows how the computed property (`countSq`) becomes part of the store's observable state and is accessible like any other state property.
Change `import computed from 'zustand-computed'` to `import { createComputed } from 'zustand-computed'`. Update usage from `create(computed(...))` to `create(createComputed(...)(...))`.No direct fix needed if upgrading to v2.1.0 or later, as the problematic Proxy behavior has been removed. Ensure your logic doesn't rely on Proxy-specific behaviors.
Ensure you are on `zustand-computed` v2.1.2 or newer, which includes specific fixes for Immer compatibility. Review middleware order, typically `immer(computed(...))` or `devtools(immer(computed(...)))`.
No direct user fix is needed for this internal change. However, if you experience bundling issues with older `zustand-computed` versions, ensure you're on a recent version. This was an internal fix.
Pass an options object to `createComputed` with `keys` (an array of state keys to watch) or `shouldRecompute` (a function comparing previous and next state) to control when recomputation occurs.
Ensure `createComputed` is imported correctly and called as a function (e.g., `create(createComputed(...)(...))`). Also, confirm `create` is imported from 'zustand' as `import { create } from 'zustand'`.Ensure your `create` call is correctly typed to include both your base `Store` type and the `ComputedStore` type. For example: `create<Store, [['chrisvander/zustand-computed', ComputedStore]]>(computed(...))`.
Update to `zustand-computed` v2.1.2 or newer to leverage bug fixes specifically for Immer compatibility. Ensure the order of middleware is correct, typically `immer(computed(...))`.