From 32d176df0ff19f10e0f111e543af05f3841bf67e Mon Sep 17 00:00:00 2001 From: Siarhei Lunski Date: Sat, 28 Sep 2024 00:06:16 +0200 Subject: [PATCH] fix: index referring to scope?.[scopeName] being undefined (#3047) --- packages/react/context/src/createContext.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/react/context/src/createContext.tsx b/packages/react/context/src/createContext.tsx index 894f298eb..fc23b7d3a 100644 --- a/packages/react/context/src/createContext.tsx +++ b/packages/react/context/src/createContext.tsx @@ -57,7 +57,7 @@ function createContextScope(scopeName: string, createContextScopeDeps: CreateSco ContextValueType & { scope: Scope; children: React.ReactNode } > = (props) => { const { scope, children, ...context } = props; - const Context = scope?.[scopeName][index] || BaseContext; + const Context = scope?.[scopeName]?.[index] || BaseContext; // Only re-memoize when prop values change // eslint-disable-next-line react-hooks/exhaustive-deps const value = React.useMemo(() => context, Object.values(context)) as ContextValueType; @@ -67,7 +67,7 @@ function createContextScope(scopeName: string, createContextScopeDeps: CreateSco Provider.displayName = rootComponentName + 'Provider'; function useContext(consumerName: string, scope: Scope) { - const Context = scope?.[scopeName][index] || BaseContext; + const Context = scope?.[scopeName]?.[index] || BaseContext; const context = React.useContext(Context); if (context) return context; if (defaultContext !== undefined) return defaultContext;