mirror of
https://github.com/pmndrs/zustand.git
synced 2025-12-08 19:45:52 +00:00
Update use-store-with-equality-fn.md (#3119)
This commit is contained in:
parent
2fcfc30530
commit
14feb61c7e
@ -709,7 +709,7 @@ given tab.
|
||||
|
||||
```tsx
|
||||
const useCounterStore = <U,>(
|
||||
currentTabIndex: number,
|
||||
key: string,
|
||||
selector: (state: CounterStore) => U,
|
||||
) => {
|
||||
const stores = useContext(CounterStoresContext)
|
||||
@ -719,15 +719,11 @@ const useCounterStore = <U,>(
|
||||
}
|
||||
|
||||
const getOrCreateCounterStoreByKey = useCallback(
|
||||
() => createCounterStoreFactory(stores),
|
||||
(key: string) => createCounterStoreFactory(stores!)(key),
|
||||
[stores],
|
||||
)
|
||||
|
||||
return useStoreWithEqualityFn(
|
||||
getOrCreateCounterStoreByKey(`tab-${currentTabIndex}`),
|
||||
selector,
|
||||
shallow,
|
||||
)
|
||||
return useStore(getOrCreateCounterStoreByKey(key), selector)
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user