From 69fd992846facea6aabcf7a15552f0cafd3f57b3 Mon Sep 17 00:00:00 2001 From: Peter Velkov Date: Mon, 2 Aug 2021 18:48:13 +0300 Subject: [PATCH 1/2] fix: `withLocalize` does not trigger a rerender in children --- src/components/withLocalize.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/components/withLocalize.js b/src/components/withLocalize.js index 4eb5ca18d6d87..c5a33ba8b211c 100755 --- a/src/components/withLocalize.js +++ b/src/components/withLocalize.js @@ -44,17 +44,19 @@ const localeProviderDefaultProps = { }; class LocaleContextProvider extends React.Component { - constructor(props) { - super(props); - - /* The context this component exposes to consumers */ - this.translateUtils = { + /** + * The context this component exposes to child components + * @returns {object} translation util functions and locale + */ + getContextValue() { + return { translate: this.translate.bind(this), numberFormat: this.numberFormat.bind(this), timestampToRelative: this.timestampToRelative.bind(this), timestampToDateTime: this.timestampToDateTime.bind(this), fromLocalPhone: this.fromLocalPhone.bind(this), toLocalPhone: this.toLocalPhone.bind(this), + locale: this.props.preferredLocale, }; } @@ -115,7 +117,7 @@ class LocaleContextProvider extends React.Component { render() { return ( - + {this.props.children} ); From 777468d6a3283884cf9b5d7d80cb699f3bc8094a Mon Sep 17 00:00:00 2001 From: Peter Velkov Date: Mon, 2 Aug 2021 19:59:51 +0300 Subject: [PATCH 2/2] Fix code style --- src/components/withLocalize.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/withLocalize.js b/src/components/withLocalize.js index c5a33ba8b211c..a5fbb53e57de3 100755 --- a/src/components/withLocalize.js +++ b/src/components/withLocalize.js @@ -139,7 +139,7 @@ export default function withLocalize(WrappedComponent) { const WithLocalize = forwardRef((props, ref) => ( {/* eslint-disable-next-line react/jsx-props-no-spreading */} - { translateUtils => } + {translateUtils => } ));