Skip to content

Commit

Permalink
updated the immer typescript middleware example to support V9 (#339)
Browse files Browse the repository at this point in the history
* updated the immer typescript middleware example to support V9

* Update readme.md

Change the comment in the Immer typescript example from `Immer V9 and above` to `Immer V9`

Co-authored-by: Daishi Kato <[email protected]>

Co-authored-by: Elia Darwish <[email protected]>
Co-authored-by: Daishi Kato <[email protected]>
  • Loading branch information
3 people authored Mar 21, 2021
1 parent 8eba484 commit 7049505
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,17 @@ For a TS example see the following [discussion](https://github.com/pmndrs/zustan
import { State, StateCreator } from 'zustand'
import produce, { Draft } from 'immer'

// Immer V8 or lower
const immer = <T extends State>(
config: StateCreator<T, (fn: (draft: Draft<T>) => void) => void>
): StateCreator<T> => (set, get, api) =>
config((fn) => set(produce(fn) as (state: T) => T), get, api)

// Immer V9
const immer = <T extends State>(
config: StateCreator<T, (fn: (draft: Draft<T>) => void) => void>
): StateCreator<T> => (set, get, api) =>
config((fn) => set(produce<T>(fn)), get, api)
```
</details>
Expand Down

0 comments on commit 7049505

Please sign in to comment.