File tree Expand file tree Collapse file tree 1 file changed +20
-5
lines changed Expand file tree Collapse file tree 1 file changed +20
-5
lines changed Original file line number Diff line number Diff line change 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'
3
7
import { useReduxContext as useDefaultReduxContext } from './useReduxContext'
8
+ import { RootStateOrAny } from '../types'
4
9
5
10
/**
6
11
* Hook factory, which creates a `useStore` hook bound to a given context.
7
12
*
8
13
* @param {React.Context } [context=ReactReduxContext] Context passed to your `<Provider>`.
9
14
* @returns {Function } A `useStore` hook bound to the specified context.
10
15
*/
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 ) {
12
21
const useReduxContext =
22
+ // @ts -ignore
13
23
context === ReactReduxContext
14
24
? useDefaultReduxContext
15
25
: ( ) => useContext ( context )
16
- return function useStore ( ) {
26
+ return function useStore <
27
+ State = S ,
28
+ Action extends BasicAction = A
29
+ // @ts -ignore
30
+ > ( ) {
17
31
const { store } = useReduxContext ( ) !
18
- return store
32
+ // @ts -ignore
33
+ return store as Store < State , Action >
19
34
}
20
35
}
21
36
You can’t perform that action at this time.
0 commit comments