diff --git a/src/components/Context.ts b/src/components/Context.ts index 8454e09f1..72e3fb10e 100644 --- a/src/components/Context.ts +++ b/src/components/Context.ts @@ -1,4 +1,4 @@ -import { createContext } from 'react' +import { createContext, version as ReactVersion } from 'react' import type { Context } from 'react' import type { Action, AnyAction, Store } from 'redux' import type { Subscription } from '../utils/Subscription' @@ -15,13 +15,17 @@ export interface ReactReduxContextValue< noopCheck: CheckFrequency } -let realContext: Context | null = null +const ContextKey = Symbol.for(`react-redux-context-${ReactVersion}`) +const gT = globalThis as { [ContextKey]?: Context } + function getContext() { + let realContext = gT[ContextKey] if (!realContext) { realContext = createContext(null as any) if (process.env.NODE_ENV !== 'production') { realContext.displayName = 'ReactRedux' } + gT[ContextKey] = realContext } return realContext }