npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

zustand-mutable

v0.3.0

Published

A sweet way to use immer-like mutable updates

Readme

zustand-mutable

build npm size

A sweet way to use immer-like mutable updates with Zustand.

Introduction

Zustand's immutable state updates can become verbose when dealing with deeply nested state. This middleware lets you write state updates using a mutable API pattern, similar to Immer's draft pattern.

Key benefit: You choose your own produce function - use Immer, Mutative, Limu, or any library that follows the produce pattern.

Installation

npm install zustand-mutable zustand

# Plus your preferred produce library (pick one):
npm install immer      # Most popular
npm install mutative   # Faster alternative
npm install limu       # Another option

Quick Start

import { create } from 'zustand'
import { mutable } from 'zustand-mutable'
import { produce } from 'immer'

type CounterState = {
  count: number
  inc: () => void
}

const useStore = create<CounterState>()(
  mutable(
    (set, get) => ({
      count: 0,
      inc: () =>
        set((state) => {
          state.count = get().count + 1 // Mutate directly!
        }),
    }),
    produce,
  ),
)

API Reference

mutable(initializer, produceFn)

Wraps your Zustand store initializer to enable mutable-style updates.

| Parameter | Type | Description | | ------------- | ------------------------------------------------- | ------------------------------------------- | | initializer | StateCreator<T> | Your standard Zustand store initializer | | produceFn | (recipe: (state: T) => void) => (state: T) => T | A produce function from your chosen library |

Supported Libraries

Immer

The most popular immutable state library.

import { produce } from 'immer'

const useStore = create<State>()(
  mutable(
    (set, get) => ({
      // your state and actions
    }),
    produce,
  ),
)

Mutative

A faster alternative to Immer with similar API.

import { create as mutativeProduce } from 'mutative'

const useStore = create<State>()(
  mutable(
    (set, get) => ({
      // your state and actions
    }),
    mutativeProduce,
  ),
)

Limu

Another immutable update library. Requires a wrapper function.

import { produce } from 'limu'

const useStore = create<State>()(
  mutable(
    (set, get) => ({
      // your state and actions
    }),
    (recipe) => produce(recipe),
  ),
)

Middleware Composition

zustand-mutable works seamlessly with other Zustand middleware.

With devtools

import { devtools } from 'zustand/middleware'

const useStore = create<CounterState>()(
  mutable(
    devtools(
      (set, get) => ({
        count: 0,
        inc: () =>
          set(
            (state) => {
              state.count = get().count + 1
            },
            false,
            { type: 'inc', by: 1 },
          ),
      }),
      { name: 'counter' },
    ),
    produce,
  ),
)

With persist

import { persist } from 'zustand/middleware'

const useStore = create<CounterState>()(
  persist(
    mutable(
      (set, get) => ({
        count: 0,
        inc: () =>
          set((state) => {
            state.count = get().count + 1
          }),
      }),
      produce,
    ),
    { name: 'counter-storage' },
  ),
)

Combining Multiple Middleware

You can stack multiple middleware together:

import { devtools, persist, subscribeWithSelector } from 'zustand/middleware'

const useStore = create<CounterState>()(
  devtools(
    subscribeWithSelector(
      persist(
        mutable(
          (set, get) => ({
            count: 0,
            inc: () =>
              set((state) => {
                state.count = get().count + 1
              }),
          }),
          produce,
        ),
        { name: 'counter' },
      ),
    ),
    { name: 'counter-devtools' },
  ),
)

TypeScript

This library is written in TypeScript and provides full type safety out of the box.

  • The Draft<T> type automatically makes your state mutable inside updater functions
  • Proper type inference is maintained through middleware composition
  • Works with strict TypeScript configurations
set((state) => {
  // `state` is typed as Draft<YourState>
  // You can mutate it directly with full type safety
  state.nested.deeply.value = 'new value'
})

Requirements

  • zustand
  • One of: immer, mutative, or limu

License

MIT