Skip to content

Commit

Permalink
docs(readme): update
Browse files Browse the repository at this point in the history
  • Loading branch information
unadlib committed May 18, 2024
1 parent 5590506 commit 7632cdf
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,46 @@
A Mutative middleware for Zustand enhances the efficiency of immutable state updates.

## Installation

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

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

## Usage

```typescript
import { create } from 'zustand'
import { mutative } from 'zustand-mutative'
import { create } from 'zustand';
import { mutative } from 'zustand-mutative';

type State = {
count: number
}
count: number;
};

type Actions = {
increment: (qty: number) => void
decrement: (qty: number) => void
}
increment: (qty: number) => void;
decrement: (qty: number) => void;
};

export const useCountStore = create<State & Actions>()(
mutative((set) => ({
count: 0,
increment: (qty: number) =>
set((state) => {
state.count += qty
state.count += qty;
}),
decrement: (qty: number) =>
set((state) => {
state.count -= qty
state.count -= qty;
}),
})),
)
}))
);
```

## Credits
`zustand-mutative` is inspired by `zustand/middleware/immer`.

## License
`zustand-mutative` is [MIT licensed](https://github.com/mutativejs/zustand-mutative/blob/main/LICENSE).

0 comments on commit 7632cdf

Please sign in to comment.