Skip to content

Commit 41838c5

Browse files
authored
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
1 parent 9baf0a5 commit 41838c5

File tree

2 files changed

+10
-23
lines changed

2 files changed

+10
-23
lines changed

docs/guides/typescript.md

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -443,15 +443,9 @@ const bearStore = createStore<BearState>()((set) => ({
443443
}))
444444

445445
function useBearStore(): BearState
446-
function useBearStore<T>(
447-
selector: (state: BearState) => T,
448-
equals?: (a: T, b: T) => boolean,
449-
): T
450-
function useBearStore<T>(
451-
selector?: (state: BearState) => T,
452-
equals?: (a: T, b: T) => boolean,
453-
) {
454-
return useStore(bearStore, selector!, equals)
446+
function useBearStore<T>(selector: (state: BearState) => T): T
447+
function useBearStore<T>(selector?: (state: BearState) => T) {
448+
return useStore(bearStore, selector!)
455449
}
456450
```
457451
@@ -471,15 +465,13 @@ const bearStore = createStore<BearState>()((set) => ({
471465
increase: (by) => set((state) => ({ bears: state.bears + by })),
472466
}))
473467

474-
const createBoundedUseStore = ((store) => (selector, equals) =>
475-
useStore(store, selector as never, equals)) as <S extends StoreApi<unknown>>(
468+
const createBoundedUseStore = ((store) => (selector) => useStore(store)) as <
469+
S extends StoreApi<unknown>,
470+
>(
476471
store: S,
477472
) => {
478473
(): ExtractState<S>
479-
<T>(
480-
selector: (state: ExtractState<S>) => T,
481-
equals?: (a: T, b: T) => boolean,
482-
): T
474+
<T>(selector: (state: ExtractState<S>) => T): T
483475
}
484476

485477
type ExtractState<S> = S extends { getState: () => infer X } ? X : never

docs/integrations/persisting-store-data.md

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ export const useBoundStore = create(
630630
)
631631
```
632632

633-
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.
633+
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.
634634

635635
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
636636

@@ -735,15 +735,10 @@ export const useBearStore = create<MyState>()(
735735

736736
### How do I use it with Map and Set
737737

738-
With the previous persist API, you would use `serialize`/`deserialize`
739-
to deal with `Map` and `Set` and convert them into
740-
an Array so they could be parsed into proper JSON.
738+
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.
741739

742-
The new persist API has deprecated `serialize`/`deserialize`.
743-
744-
Now, you will need to use the `storage` prop.
745740
Let's say your state uses `Map` to handle a list of `transactions`,
746-
then you can convert the Map into an Array in the storage prop:
741+
then you can convert the `Map` into an `Array` in the `storage` prop which is shown below:
747742

748743
```ts
749744

0 commit comments

Comments
 (0)