Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A Mutative middleware for Zustand enhances the efficiency of immutable state updates.

License

NotificationsYou must be signed in to change notification settings

mutativejs/zustand-mutative

Repository files navigation

Node CInpmlicense

AMutative middleware for Zustand enhances the efficiency of immutable state updates.

With the Mutative middleware, you can simplify the handling of immutable data in Zustand in a mutable way, allowing you to use immutable state more conveniently.

zustand-mutative is 2-6x faster than zustand with spread operation, more than 10x faster thanzustand/middleware/immer.Read more about the performance comparison in Mutative.

Benchmarks

Measure(ops/sec) to update 50K arrays and 1K objects, bigger is better(view source). [Mutative v1.3.0 vs Immer v10.1.3]

Benchmark

Zustand with Mutative - Update big array and object x 5,236 ops/sec ±2.39% (83 runs sampled)Zustand with Immer - Update big array and object x 255 ops/sec ±0.23% (87 runs sampled)The fastest method is Zustand with Mutative - Update big array and object

Installation

In order to use the Mutative middleware in Zustand, you will need to install Mutative and Zustand as a direct dependency.

npm install zustand-mutative zustand mutative# Or use any package manager of your choice.

Usage

import{create}from'zustand';import{mutative}from'zustand-mutative';typeState={count:number;};typeActions={increment:(qty:number)=>void;decrement:(qty:number)=>void;};exportconstuseCountStore=create<State&Actions>()(mutative((set)=>({count:0,increment:(qty:number)=>set((state)=>{state.count+=qty;}),decrement:(qty:number)=>set((state)=>{state.count-=qty;}),})));

Mutative Options

Credits

zustand-mutative is inspired byzustand/middleware/immer.

License

zustand-mutative isMIT licensed.

About

A Mutative middleware for Zustand enhances the efficiency of immutable state updates.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors2

  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp