Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: index referring to scope?.[scopeName] being undefined #3047

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/react/context/src/createContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ function createContextScope(scopeName: string, createContextScopeDeps: CreateSco
props: ContextValueType & { scope: Scope<ContextValueType>; 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;
return <Context.Provider value={value}>{children}</Context.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