mirror of
https://github.com/pmndrs/zustand.git
synced 2025-12-08 19:45:52 +00:00
fix(context): store property missing from useStoreApi (#1258)
This commit is contained in:
parent
276af10d88
commit
43ea18e768
@ -44,7 +44,7 @@ function createContext<S extends StoreApi<unknown>>() {
|
||||
)
|
||||
}
|
||||
|
||||
const useBoundStore = (<StateSlice = ExtractState<S>>(
|
||||
const useContextStore: UseContextStore<S> = <StateSlice = ExtractState<S>>(
|
||||
selector?: (state: ExtractState<S>) => StateSlice,
|
||||
equalityFn?: (a: StateSlice, b: StateSlice) => boolean
|
||||
) => {
|
||||
@ -59,7 +59,7 @@ function createContext<S extends StoreApi<unknown>>() {
|
||||
selector as (state: ExtractState<S>) => StateSlice,
|
||||
equalityFn
|
||||
)
|
||||
}) as UseContextStore<S>
|
||||
}
|
||||
|
||||
const useStoreApi = () => {
|
||||
const store = useContext(ZustandContext)
|
||||
@ -68,21 +68,12 @@ function createContext<S extends StoreApi<unknown>>() {
|
||||
'Seems like you have not used zustand provider as an ancestor.'
|
||||
)
|
||||
}
|
||||
return useMemo(
|
||||
() =>
|
||||
({
|
||||
getState: store.getState,
|
||||
setState: store.setState,
|
||||
subscribe: store.subscribe,
|
||||
destroy: store.destroy,
|
||||
} as WithoutCallSignature<S>),
|
||||
[store]
|
||||
)
|
||||
return useMemo<WithoutCallSignature<S>>(() => ({ ...store }), [store])
|
||||
}
|
||||
|
||||
return {
|
||||
Provider,
|
||||
useStore: useBoundStore,
|
||||
useStore: useContextStore,
|
||||
useStoreApi,
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user