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