docs(typescript): fix bounded use store example (#1779)

* test: changer

* docs: fix abstract bounded store hook TS example

Fixes type issues due to optional arg:
https://github.com/pmndrs/zustand/discussions/1564#discussioncomment-5735802

* fix: pr feedback
This commit is contained in:
Daniels L 2023-04-28 01:40:42 -07:00 committed by GitHub
parent 513b22283e
commit e71e313bd7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -428,7 +428,7 @@ function useBearStore<T>(
}
```
You can also make an abstract `createBoundedUseStore` if you create bounded `useStore`s often and want to DRY things up...
You can also make an abstract `createBoundedUseStore` function if you need to create bounded `useStore` hooks often and want to DRY things up...
```ts
import { useStore, StoreApi } from 'zustand'
@ -445,12 +445,12 @@ const bearStore = createStore<BearState>()((set) => ({
}))
const createBoundedUseStore = ((store) => (selector, equals) =>
useStore(store, selector as any, equals)) as <S extends StoreApi<unknown>>(
useStore(store, selector as never, equals)) as <S extends StoreApi<unknown>>(
store: S
) => {
(): ExtractState<S>
<T>(
selector?: (state: ExtractState<S>) => T,
selector: (state: ExtractState<S>) => T,
equals?: (a: T, b: T) => boolean
): T
}