chore(docs): rewrite to remove deprecated references in persist docs (#2248)

* chore(docs): rewrite to remove deprecated references in persist docs

* chore(docs): remove deprecated equalityFn
This commit is contained in:
Charles Kornoelje 2023-12-13 17:05:20 -06:00 committed by GitHub
parent 9baf0a5d38
commit 41838c5187
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 23 deletions

View File

@ -443,15 +443,9 @@ const bearStore = createStore<BearState>()((set) => ({
}))
function useBearStore(): BearState
function useBearStore<T>(
selector: (state: BearState) => T,
equals?: (a: T, b: T) => boolean,
): T
function useBearStore<T>(
selector?: (state: BearState) => T,
equals?: (a: T, b: T) => boolean,
) {
return useStore(bearStore, selector!, equals)
function useBearStore<T>(selector: (state: BearState) => T): T
function useBearStore<T>(selector?: (state: BearState) => T) {
return useStore(bearStore, selector!)
}
```
@ -471,15 +465,13 @@ const bearStore = createStore<BearState>()((set) => ({
increase: (by) => set((state) => ({ bears: state.bears + by })),
}))
const createBoundedUseStore = ((store) => (selector, equals) =>
useStore(store, selector as never, equals)) as <S extends StoreApi<unknown>>(
const createBoundedUseStore = ((store) => (selector) => useStore(store)) as <
S extends StoreApi<unknown>,
>(
store: S,
) => {
(): ExtractState<S>
<T>(
selector: (state: ExtractState<S>) => T,
equals?: (a: T, b: T) => boolean,
): T
<T>(selector: (state: ExtractState<S>) => T): T
}
type ExtractState<S> = S extends { getState: () => infer X } ? X : never

View File

@ -630,7 +630,7 @@ export const useBoundStore = create(
)
```
If you're using a type that JSON.stringify() doesn't support, you'll need to write your own serialization/deserialization code. However, if this is tedious, you can use third-party libraries to serialize and deserialize different types of data.
If you're using a type that `JSON.stringify()` doesn't support, you'll need to write your own serialization/deserialization code. However, if this is tedious, you can use third-party libraries to serialize and deserialize different types of data.
For example, [Superjson](https://github.com/blitz-js/superjson) can serialize data along with its type, allowing the data to be parsed back to its original type upon deserialization
@ -735,15 +735,10 @@ export const useBearStore = create<MyState>()(
### How do I use it with Map and Set
With the previous persist API, you would use `serialize`/`deserialize`
to deal with `Map` and `Set` and convert them into
an Array so they could be parsed into proper JSON.
In order to persist object types such as `Map` and `Set`, they will need to be converted to JSON-serializable types such as an `Array` which can be done by defining a custom `storage` engine.
The new persist API has deprecated `serialize`/`deserialize`.
Now, you will need to use the `storage` prop.
Let's say your state uses `Map` to handle a list of `transactions`,
then you can convert the Map into an Array in the storage prop:
then you can convert the `Map` into an `Array` in the `storage` prop which is shown below:
```ts