Skip to content

Commit 82b0bce

Browse files
committed
Add missing generics to useStore hook
1 parent ddab3b1 commit 82b0bce

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

src/hooks/useStore.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,36 @@
1-
import { useContext } from 'react'
2-
import { ReactReduxContext } from '../components/Context'
1+
import { useContext, Context } from 'react'
2+
import { Action as BasicAction, AnyAction, Store } from 'redux'
3+
import {
4+
ReactReduxContext,
5+
ReactReduxContextValue,
6+
} from '../components/Context'
37
import { useReduxContext as useDefaultReduxContext } from './useReduxContext'
8+
import { RootStateOrAny } from '../types'
49

510
/**
611
* Hook factory, which creates a `useStore` hook bound to a given context.
712
*
813
* @param {React.Context} [context=ReactReduxContext] Context passed to your `<Provider>`.
914
* @returns {Function} A `useStore` hook bound to the specified context.
1015
*/
11-
export function createStoreHook(context = ReactReduxContext) {
16+
export function createStoreHook<
17+
S = RootStateOrAny,
18+
A extends BasicAction = AnyAction
19+
// @ts-ignore
20+
>(context?: Context<ReactReduxContextValue<S, A>> = ReactReduxContext) {
1221
const useReduxContext =
22+
// @ts-ignore
1323
context === ReactReduxContext
1424
? useDefaultReduxContext
1525
: () => useContext(context)
16-
return function useStore() {
26+
return function useStore<
27+
State = S,
28+
Action extends BasicAction = A
29+
// @ts-ignore
30+
>() {
1731
const { store } = useReduxContext()!
18-
return store
32+
// @ts-ignore
33+
return store as Store<State, Action>
1934
}
2035
}
2136

0 commit comments

Comments
 (0)