From 63e19ce94afa1f97675b06ea14b9335f7f231900 Mon Sep 17 00:00:00 2001 From: SummerOverture <740834798@qq.com> Date: Tue, 29 Dec 2020 11:08:56 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E9=AB=98=E9=98=B6?= =?UTF-8?q?=E7=BB=84=E4=BB=B6ref=E9=80=8F=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/components/Config/Locale/WithLocale.tsx | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/source/components/Config/Locale/WithLocale.tsx b/source/components/Config/Locale/WithLocale.tsx index a461e3e5b..3c8dd5da8 100644 --- a/source/components/Config/Locale/WithLocale.tsx +++ b/source/components/Config/Locale/WithLocale.tsx @@ -11,14 +11,16 @@ function getDisplayName(WrappedComponent) { const withLocale = ({ componentName }) => (WrappedComponent: React.ComponentType): any => { - type WithLocaleProps = WrappedProps; + type WithLocaleProps = WrappedProps & { + forwardRef: any, + }; type WithLocaleState = { Locale?: object }; class WithLocale extends Component { static displayName: string; - constructor (props) { + constructor(props) { super(props); this.state = { @@ -27,12 +29,14 @@ const withLocale = ({ componentName }) => } render() { + const { forwardRef, ...otherProps } = this.props; return ( { (Locale) => } @@ -40,8 +44,12 @@ const withLocale = ({ componentName }) => ); } } + WithLocale.displayName = `WithLocale(${getDisplayName(WrappedComponent)})`; - return hoistNonReactStatic(WithLocale, WrappedComponent); + return React.forwardRef(function WithLocaleRef(props, ref) { + const WithLocaleRef = hoistNonReactStatic(WithLocale, WrappedComponent) + return ; + }); }; export default withLocale;