mirror of
https://github.com/pmndrs/zustand.git
synced 2025-12-08 19:45:52 +00:00
Update Recipes persist example to match example in Persisting Store Data integration (#1813)
Replace the deprecated `getStorage` option with the new `storage` option with `createJSONStorage`.
This commit is contained in:
parent
286e4436c7
commit
d61b70fd8d
@ -320,7 +320,7 @@ You can persist your store's data using any kind of storage.
|
||||
|
||||
```jsx
|
||||
import { create } from 'zustand'
|
||||
import { persist } from 'zustand/middleware'
|
||||
import { persist, createJSONStorage } from 'zustand/middleware'
|
||||
|
||||
export const useStore = create(
|
||||
persist(
|
||||
@ -329,8 +329,8 @@ export const useStore = create(
|
||||
addAFish: () => set({ fishes: get().fishes + 1 }),
|
||||
}),
|
||||
{
|
||||
name: 'food-storage', // unique name
|
||||
getStorage: () => sessionStorage, // (optional) by default the 'localStorage' is used
|
||||
name: 'food-storage', // name of the item in the storage (must be unique)
|
||||
storage: createJSONStorage(() => sessionStorage), // (optional) by default, 'localStorage' is used
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user