Update persist documentation for storage (#1521)

This replaces `getStorage` with `storage`.

This PR raises two questions:
- Should we write documentation on how to migrate from the `getStorage` API to the `storage` API?
- Should we version the middleware separately from the zustand core?
This commit is contained in:
Charles Kornoelje 2023-01-09 18:09:01 -05:00 committed by GitHub
parent 820dbd35ea
commit 86c5016e28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -300,7 +300,7 @@ Or even to change the storage engine:
```ts
useBoundStore.persist.setOptions({
getStorage: () => sessionStorage,
storage: createJSONStorage(() => sessionStorage),
})
```
@ -511,7 +511,7 @@ export const useBoundStore = create(
}),
{
name: 'food-storage', // unique name
getStorage: () => storage,
storage: createJSONStorage(() => storage),
}
)
)
@ -565,7 +565,7 @@ export const useBearStore = create<MyState>()(
}),
{
name: 'food-storage', // name of item in the storage (must be unique)
getStorage: () => sessionStorage, // (optional) by default the 'localStorage' is used
storage: createJSONStorage(() => sessionStorage), // (optional) by default the 'localStorage' is used
partialize: (state) => ({ bears: state.bears }),
}
)