From d67e2f621c6a4833ee14638f37bc0f1bf2b0102f Mon Sep 17 00:00:00 2001 From: Siarhei Lunski Date: Sat, 3 Aug 2024 17:40:09 +0200 Subject: [PATCH] fix: missing scope referring --- 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 e3ca734f7..01e35ba65 100644 --- a/packages/react/context/src/createContext.tsx +++ b/packages/react/context/src/createContext.tsx @@ -56,7 +56,7 @@ function createContextScope(scopeName: string, createContextScopeDeps: CreateSco props: ContextValueType & { scope: Scope; children: React.ReactNode } ) { 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; @@ -64,7 +64,7 @@ function createContextScope(scopeName: string, createContextScopeDeps: CreateSco } 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;