mirror of
https://github.com/pmndrs/zustand.git
synced 2025-12-08 19:45:52 +00:00
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:
parent
513b22283e
commit
e71e313bd7
@ -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
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user