mirror of
https://github.com/pmndrs/zustand.git
synced 2025-12-08 19:45:52 +00:00
docs: Update typescript guide persist examples... (#2001)
* docs: Update typescript guide persist examples to add required name option * docs: run prettier * docs: reverting prettier changes to testing.md * docs: Update docs/guides/typescript.md per review comment. Co-authored-by: Blazej Sewera <code@sewera.dev> * docs: Update docs/guides/typescript.md per review comment and zustand conventions. Co-authored-by: Blazej Sewera <code@sewera.dev> * docs: change persist options name property to bearStore for consistency. --------- Co-authored-by: John Gilliland <John.Gilliland@Starz.com> Co-authored-by: Blazej Sewera <code@sewera.dev>
This commit is contained in:
parent
0058a03b78
commit
9ddfced2ea
@ -176,10 +176,13 @@ 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: 'bearStore' }
|
||||
)
|
||||
)
|
||||
)
|
||||
```
|
||||
@ -190,7 +193,7 @@ Just make sure you are using them immediately inside `create` so as to make the
|
||||
import { create } from 'zustand'
|
||||
import { devtools, persist } from 'zustand/middleware'
|
||||
|
||||
const myMiddlewares = (f) => devtools(persist(f))
|
||||
const myMiddlewares = (f) => devtools(persist(f, { name: 'bearStore' }))
|
||||
|
||||
interface BearState {
|
||||
bears: number
|
||||
@ -351,7 +354,7 @@ const useBearStore = create<
|
||||
>(devtools(persist((set) => ({
|
||||
bears: 0,
|
||||
increase: (by) => set((state) => ({ bears: state.bears + by })),
|
||||
})))
|
||||
}), { name: 'bearStore' }))
|
||||
```
|
||||
|
||||
### Slices pattern
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user