Skip to content

Commit

Permalink
fix: index referring to scope?.[scopeName] being undefined (#3047)
Browse files Browse the repository at this point in the history
  • Loading branch information
loonskai authored Sep 27, 2024
1 parent 5d7b5fb commit 32d176d
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/react/context/src/createContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function createContextScope(scopeName: string, createContextScopeDeps: CreateSco
ContextValueType & { scope: Scope<ContextValueType>; 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;
Expand All @@ -67,7 +67,7 @@ function createContextScope(scopeName: string, createContextScopeDeps: CreateSco
Provider.displayName = rootComponentName + 'Provider';

function useContext(consumerName: string, scope: Scope<ContextValueType | undefined>) {
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;
Expand Down

0 comments on commit 32d176d

Please sign in to comment.