Skip to content

Commit

Permalink
Fix Persist in TypeScript Usage on readme (pmndrs#1193)
Browse files Browse the repository at this point in the history
* Fix Persist example in Typescript

Persist middleware requires the name option to keep storage unique.

See https://github.com/pmndrs/zustand/blob/main/docs/persisting-store-data.md#name

This change adds the 'name' option to the Typescript Usage example to update it.
Additionally, the persist example already has this required option.

* run prettier on file
  • Loading branch information
spenceradolph authored Aug 18, 2022
1 parent 75d0886 commit f0b6023
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -461,10 +461,15 @@ interface BearState {

const useBearStore = create<BearState>()(
devtools(
persist((set) => ({
bears: 0,
increase: (by) => set((state) => ({ bears: state.bears + by })),
}))
persist(
(set) => ({
bears: 0,
increase: (by) => set((state) => ({ bears: state.bears + by })),
}),
{
name: 'bear-storage',
}
)
)
)
```
Expand Down

0 comments on commit f0b6023

Please sign in to comment.