diff --git a/docs/guides/typescript.md b/docs/guides/typescript.md index f3188a9e8..1f9432f4b 100644 --- a/docs/guides/typescript.md +++ b/docs/guides/typescript.md @@ -443,15 +443,9 @@ const bearStore = createStore()((set) => ({ })) function useBearStore(): BearState -function useBearStore( - selector: (state: BearState) => T, - equals?: (a: T, b: T) => boolean, -): T -function useBearStore( - selector?: (state: BearState) => T, - equals?: (a: T, b: T) => boolean, -) { - return useStore(bearStore, selector!, equals) +function useBearStore(selector: (state: BearState) => T): T +function useBearStore(selector?: (state: BearState) => T) { + return useStore(bearStore, selector!) } ``` @@ -471,15 +465,13 @@ const bearStore = createStore()((set) => ({ increase: (by) => set((state) => ({ bears: state.bears + by })), })) -const createBoundedUseStore = ((store) => (selector, equals) => - useStore(store, selector as never, equals)) as >( +const createBoundedUseStore = ((store) => (selector) => useStore(store)) as < + S extends StoreApi, +>( store: S, ) => { (): ExtractState - ( - selector: (state: ExtractState) => T, - equals?: (a: T, b: T) => boolean, - ): T + (selector: (state: ExtractState) => T): T } type ExtractState = S extends { getState: () => infer X } ? X : never diff --git a/docs/integrations/persisting-store-data.md b/docs/integrations/persisting-store-data.md index 5929e6ccb..8c3342a0a 100644 --- a/docs/integrations/persisting-store-data.md +++ b/docs/integrations/persisting-store-data.md @@ -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()( ### 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