chore: 优化 locale, theme hoc, 存在 context 直接复用 (#5702)

* publish beta

* chore: 优化 locale, theme hoc, 存在 context 直接复用
This commit is contained in:
liaoxuezhi 2022-11-08 10:22:49 +08:00 committed by GitHub
parent 723c6bf4eb
commit a6592c7d28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 23 deletions

View File

@ -128,17 +128,21 @@ export function localeable<
const refConfig = ComposedComponent.prototype?.isReactComponent
? {ref: this.childRef}
: {forwardedRef: this.childRef};
return (
<LocaleContext.Provider value={locale}>
<ComposedComponent
{...(this.props as JSX.LibraryManagedAttributes<
T,
React.ComponentProps<T>
> as any)}
{...injectedProps}
{...refConfig}
/>
</LocaleContext.Provider>
const body = (
<ComposedComponent
{...(this.props as JSX.LibraryManagedAttributes<
T,
React.ComponentProps<T>
> as any)}
{...injectedProps}
{...refConfig}
/>
);
return this.context ? (
body
) : (
<LocaleContext.Provider value={locale}>{body}</LocaleContext.Provider>
);
}
},

View File

@ -191,18 +191,22 @@ export function themeable<
? {ref: this.childRef}
: {forwardedRef: this.childRef};
return (
<ThemeContext.Provider value={theme}>
<ComposedComponent
{...config.getComponentConfig(ComposedComponent.themeKey)}
{...(this.props as JSX.LibraryManagedAttributes<
T,
React.ComponentProps<T>
>)}
{...injectedProps}
{...refConfig}
/>
</ThemeContext.Provider>
const body = (
<ComposedComponent
{...config.getComponentConfig(ComposedComponent.themeKey)}
{...(this.props as JSX.LibraryManagedAttributes<
T,
React.ComponentProps<T>
>)}
{...injectedProps}
{...refConfig}
/>
);
return this.context ? (
body
) : (
<ThemeContext.Provider value={theme}>{body}</ThemeContext.Provider>
);
}
},