From 07c1a59e24a306280220860f0b2c46f5fcb33d73 Mon Sep 17 00:00:00 2001 From: Wonsuk Choi Date: Thu, 22 Aug 2024 12:54:29 +0900 Subject: [PATCH 1/2] refactor(context): add React.FC type in Provider --- packages/react/context/src/createContext.tsx | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/react/context/src/createContext.tsx b/packages/react/context/src/createContext.tsx index e3ca734f7..894f298eb 100644 --- a/packages/react/context/src/createContext.tsx +++ b/packages/react/context/src/createContext.tsx @@ -6,13 +6,15 @@ function createContext( ) { const Context = React.createContext(defaultContext); - function Provider(props: ContextValueType & { children: React.ReactNode }) { + const Provider: React.FC = (props) => { const { children, ...context } = props; // 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 {children}; - } + }; + + Provider.displayName = rootComponentName + 'Provider'; function useContext(consumerName: string) { const context = React.useContext(Context); @@ -22,7 +24,6 @@ function createContext( throw new Error(`\`${consumerName}\` must be used within \`${rootComponentName}\``); } - Provider.displayName = rootComponentName + 'Provider'; return [Provider, useContext] as const; } @@ -52,16 +53,18 @@ function createContextScope(scopeName: string, createContextScopeDeps: CreateSco const index = defaultContexts.length; defaultContexts = [...defaultContexts, defaultContext]; - function Provider( - props: ContextValueType & { scope: Scope; children: React.ReactNode } - ) { + const Provider: React.FC< + ContextValueType & { scope: Scope; children: React.ReactNode } + > = (props) => { const { scope, children, ...context } = props; 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 {children}; - } + }; + + Provider.displayName = rootComponentName + 'Provider'; function useContext(consumerName: string, scope: Scope) { const Context = scope?.[scopeName][index] || BaseContext; @@ -72,7 +75,6 @@ function createContextScope(scopeName: string, createContextScopeDeps: CreateSco throw new Error(`\`${consumerName}\` must be used within \`${rootComponentName}\``); } - Provider.displayName = rootComponentName + 'Provider'; return [Provider, useContext] as const; } From 01cac0f8a3557e2c806f69f06cbf90c9d59de66d Mon Sep 17 00:00:00 2001 From: Wonsuk Choi Date: Thu, 22 Aug 2024 12:57:43 +0900 Subject: [PATCH 2/2] chore(.yarn/versions): track versions --- .yarn/versions/c80771b8.yml | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 .yarn/versions/c80771b8.yml diff --git a/.yarn/versions/c80771b8.yml b/.yarn/versions/c80771b8.yml new file mode 100644 index 000000000..8216d98bb --- /dev/null +++ b/.yarn/versions/c80771b8.yml @@ -0,0 +1,33 @@ +releases: + "@radix-ui/react-context": patch + +declined: + - primitives + - "@radix-ui/react-accordion" + - "@radix-ui/react-alert-dialog" + - "@radix-ui/react-avatar" + - "@radix-ui/react-checkbox" + - "@radix-ui/react-collapsible" + - "@radix-ui/react-collection" + - "@radix-ui/react-context-menu" + - "@radix-ui/react-dialog" + - "@radix-ui/react-dropdown-menu" + - "@radix-ui/react-form" + - "@radix-ui/react-hover-card" + - "@radix-ui/react-menu" + - "@radix-ui/react-menubar" + - "@radix-ui/react-navigation-menu" + - "@radix-ui/react-popover" + - "@radix-ui/react-popper" + - "@radix-ui/react-progress" + - "@radix-ui/react-radio-group" + - "@radix-ui/react-roving-focus" + - "@radix-ui/react-scroll-area" + - "@radix-ui/react-select" + - "@radix-ui/react-slider" + - "@radix-ui/react-switch" + - "@radix-ui/react-tabs" + - "@radix-ui/react-toast" + - "@radix-ui/react-toggle-group" + - "@radix-ui/react-toolbar" + - "@radix-ui/react-tooltip"