{"id":35535764,"url":"https://github.com/zustandjs/zustand-mutable","last_synced_at":"2026-02-05T12:06:06.739Z","repository":{"id":332408657,"uuid":"1126954066","full_name":"zustandjs/zustand-mutable","owner":"zustandjs","description":"A sweet way to use immer-like mutable updates","archived":false,"fork":false,"pushed_at":"2026-01-04T02:03:54.000Z","size":104,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-01-13T19:44:06.836Z","etag":null,"topics":["immer","limu","middleware","mutative","zustand","zustand-middleware"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zustandjs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-01-02T22:07:57.000Z","updated_at":"2026-01-04T02:03:57.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/zustandjs/zustand-mutable","commit_stats":null,"previous_names":["zustandjs/zustand-mutable"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/zustandjs/zustand-mutable","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zustandjs%2Fzustand-mutable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zustandjs%2Fzustand-mutable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zustandjs%2Fzustand-mutable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zustandjs%2Fzustand-mutable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zustandjs","download_url":"https://codeload.github.com/zustandjs/zustand-mutable/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zustandjs%2Fzustand-mutable/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29121683,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-05T10:47:47.471Z","status":"ssl_error","status_checked_at":"2026-02-05T10:45:08.119Z","response_time":65,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["immer","limu","middleware","mutative","zustand","zustand-middleware"],"created_at":"2026-01-04T03:20:20.582Z","updated_at":"2026-02-05T12:06:06.726Z","avatar_url":"https://github.com/zustandjs.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# zustand-mutable\n\n[![build](https://img.shields.io/github/actions/workflow/status/zustandjs/zustand-mutable/test.yml?branch=main)](https://github.com/zustandjs/zustand-mutable/actions?query=workflow%3ACI)\n[![npm](https://img.shields.io/npm/v/zustand-mutable)](https://www.npmjs.com/package/zustand-mutable)\n[![size](https://img.shields.io/bundlephobia/minzip/zustand-mutable)](https://bundlephobia.com/result?p=zustand-mutable)\n\nA sweet way to use immer-like mutable updates with Zustand.\n\n## Introduction\n\nZustand'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.\n\n**Key benefit:** You choose your own produce function - use [Immer](https://github.com/immerjs/immer), [Mutative](https://github.com/unadlib/mutative), [Limu](https://github.com/tnfe/limu), or any library that follows the produce pattern.\n\n## Installation\n\n```bash\nnpm install zustand-mutable zustand\n\n# Plus your preferred produce library (pick one):\nnpm install immer      # Most popular\nnpm install mutative   # Faster alternative\nnpm install limu       # Another option\n```\n\n## Quick Start\n\n```typescript\nimport { create } from 'zustand'\nimport { mutable } from 'zustand-mutable'\nimport { produce } from 'immer'\n\ntype CounterState = {\n  count: number\n  inc: () =\u003e void\n}\n\nconst useStore = create\u003cCounterState\u003e()(\n  mutable(\n    (set, get) =\u003e ({\n      count: 0,\n      inc: () =\u003e\n        set((state) =\u003e {\n          state.count = get().count + 1 // Mutate directly!\n        }),\n    }),\n    produce,\n  ),\n)\n```\n\n## API Reference\n\n### `mutable(initializer, produceFn)`\n\nWraps your Zustand store initializer to enable mutable-style updates.\n\n| Parameter     | Type                                              | Description                                 |\n| ------------- | ------------------------------------------------- | ------------------------------------------- |\n| `initializer` | `StateCreator\u003cT\u003e`                                 | Your standard Zustand store initializer     |\n| `produceFn`   | `(recipe: (state: T) =\u003e void) =\u003e (state: T) =\u003e T` | A produce function from your chosen library |\n\n## Supported Libraries\n\n### Immer\n\nThe most popular immutable state library.\n\n```typescript\nimport { produce } from 'immer'\n\nconst useStore = create\u003cState\u003e()(\n  mutable(\n    (set, get) =\u003e ({\n      // your state and actions\n    }),\n    produce,\n  ),\n)\n```\n\n### Mutative\n\nA faster alternative to Immer with similar API.\n\n```typescript\nimport { create as mutativeProduce } from 'mutative'\n\nconst useStore = create\u003cState\u003e()(\n  mutable(\n    (set, get) =\u003e ({\n      // your state and actions\n    }),\n    mutativeProduce,\n  ),\n)\n```\n\n### Limu\n\nAnother immutable update library. Requires a wrapper function.\n\n```typescript\nimport { produce } from 'limu'\n\nconst useStore = create\u003cState\u003e()(\n  mutable(\n    (set, get) =\u003e ({\n      // your state and actions\n    }),\n    (recipe) =\u003e produce(recipe),\n  ),\n)\n```\n\n## Middleware Composition\n\n`zustand-mutable` works seamlessly with other Zustand middleware.\n\n### With devtools\n\n```typescript\nimport { devtools } from 'zustand/middleware'\n\nconst useStore = create\u003cCounterState\u003e()(\n  mutable(\n    devtools(\n      (set, get) =\u003e ({\n        count: 0,\n        inc: () =\u003e\n          set(\n            (state) =\u003e {\n              state.count = get().count + 1\n            },\n            false,\n            { type: 'inc', by: 1 },\n          ),\n      }),\n      { name: 'counter' },\n    ),\n    produce,\n  ),\n)\n```\n\n### With persist\n\n```typescript\nimport { persist } from 'zustand/middleware'\n\nconst useStore = create\u003cCounterState\u003e()(\n  persist(\n    mutable(\n      (set, get) =\u003e ({\n        count: 0,\n        inc: () =\u003e\n          set((state) =\u003e {\n            state.count = get().count + 1\n          }),\n      }),\n      produce,\n    ),\n    { name: 'counter-storage' },\n  ),\n)\n```\n\n### Combining Multiple Middleware\n\nYou can stack multiple middleware together:\n\n```typescript\nimport { devtools, persist, subscribeWithSelector } from 'zustand/middleware'\n\nconst useStore = create\u003cCounterState\u003e()(\n  devtools(\n    subscribeWithSelector(\n      persist(\n        mutable(\n          (set, get) =\u003e ({\n            count: 0,\n            inc: () =\u003e\n              set((state) =\u003e {\n                state.count = get().count + 1\n              }),\n          }),\n          produce,\n        ),\n        { name: 'counter' },\n      ),\n    ),\n    { name: 'counter-devtools' },\n  ),\n)\n```\n\n## TypeScript\n\nThis library is written in TypeScript and provides full type safety out of the box.\n\n- The `Draft\u003cT\u003e` type automatically makes your state mutable inside updater functions\n- Proper type inference is maintained through middleware composition\n- Works with strict TypeScript configurations\n\n```typescript\nset((state) =\u003e {\n  // `state` is typed as Draft\u003cYourState\u003e\n  // You can mutate it directly with full type safety\n  state.nested.deeply.value = 'new value'\n})\n```\n\n## Requirements\n\n- `zustand`\n- One of: `immer`, `mutative`, or `limu`\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzustandjs%2Fzustand-mutable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzustandjs%2Fzustand-mutable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzustandjs%2Fzustand-mutable/lists"}