1
- import { createContext } from 'react'
1
+ import { Context , createContext } from 'react'
2
2
import type { Action , AnyAction , Store } from 'redux'
3
3
import type { Subscription } from '../utils/Subscription'
4
4
import { StabilityCheck } from '../hooks/useSelector'
@@ -13,13 +13,31 @@ export interface ReactReduxContextValue<
13
13
stabilityCheck : StabilityCheck
14
14
}
15
15
16
- export const ReactReduxContext =
17
- /*#__PURE__*/ createContext < ReactReduxContextValue > ( null as any )
16
+ let realContext : Context < ReactReduxContextValue > | null = null
17
+ function getContext ( ) {
18
+ if ( ! realContext ) {
19
+ realContext = createContext < ReactReduxContextValue > ( null as any )
20
+ if ( process . env . NODE_ENV !== 'production' ) {
21
+ realContext . displayName = 'ReactRedux'
22
+ }
23
+ }
24
+ return realContext
25
+ }
18
26
19
- export type ReactReduxContextInstance = typeof ReactReduxContext
27
+ export const ReactReduxContext = /*#__PURE__*/ new Proxy (
28
+ { } as Context < ReactReduxContextValue > ,
29
+ new Proxy < ProxyHandler < Context < ReactReduxContextValue > > > (
30
+ { } ,
31
+ {
32
+ get ( _ , handler ) {
33
+ const target = getContext ( )
34
+ // @ts -ignore
35
+ return ( _target , ...args ) => Reflect [ handler ] ( target , ...args )
36
+ } ,
37
+ }
38
+ )
39
+ )
20
40
21
- if ( process . env . NODE_ENV !== 'production' ) {
22
- ReactReduxContext . displayName = 'ReactRedux'
23
- }
41
+ export type ReactReduxContextInstance = typeof ReactReduxContext
24
42
25
43
export default ReactReduxContext
0 commit comments