Skip to content

Commit

Permalink
chore: updated readme with middleware section
Browse files Browse the repository at this point in the history
  • Loading branch information
Albert-Gao committed Jul 26, 2022
1 parent 205fad7 commit b03ed75
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<img src="https://badgen.net/twitter/follow/albertgao"/>
</a>

**Stop writing selectors and do more work!**
**Enjoy the performance gain of selectors without writing selectors!**

## Features

Expand All @@ -58,10 +58,12 @@ yarn add auto-zustand-selectors-hook

## Notice

The v2 supports Zustand v4, if you are using a Zustand v3, please install the v1 version
The `v2` supports `Zustand v4`, if you are using a `Zustand v3`, please install the `v1` version

```bash
yarn add auto-zustand-selectors-hook@1.0.1

npm install --save auto-zustand-selectors-hook@1.0.1
```

## Usage
Expand Down Expand Up @@ -144,6 +146,25 @@ const TestComponent = () => {
};
```

## 3. use with middlewares

> You use the middleware for creating the base store, and `ALWAYS` use `auto-zustand-selectors-hooks` as a separate wrapper
```typescript
import { createSelectorHooks } from '../src/index';
import create from 'zustand';
import { persist } from 'zustand/middleware';

const useStoreBase = create<BearState>()(
persist((set) => ({
bears: 0,
increase: (by) => set((state) => ({ bears: state.bears + by })),
}))
);

export const useStore = createSelectorHooks(useStoreBase);
```

## License

MIT © [Albert Gao](https://github.com/Albert-Gao)
Expand Down

0 comments on commit b03ed75

Please sign in to comment.