Skip to content

Commit d80999e

Browse files
IgnusGsnowystingeryihuiliao
authored
Cache locale dict lest child hooks always re-render (#6185)
* Cache locale dict lest child hooks always re-render * Update context.tsx * fix lint --------- Co-authored-by: Robert Snow <[email protected]> Co-authored-by: Robert Snow <[email protected]> Co-authored-by: Yihui Liao <[email protected]>
1 parent b294de8 commit d80999e

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

packages/@react-aria/i18n/src/context.tsx

+10-4
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,16 @@ export function I18nProvider(props: I18nProviderProps) {
3030
let {locale, children} = props;
3131
let defaultLocale = useDefaultLocale();
3232

33-
let value: Locale = locale ? {
34-
locale,
35-
direction: isRTL(locale) ? 'rtl' : 'ltr'
36-
} : defaultLocale;
33+
let value: Locale = React.useMemo(() => {
34+
if (!locale) {
35+
return defaultLocale;
36+
}
37+
38+
return {
39+
locale,
40+
direction: isRTL(locale) ? 'rtl' : 'ltr'
41+
};
42+
}, [defaultLocale, locale]);
3743

3844
return (
3945
<I18nContext.Provider value={value}>

0 commit comments

Comments
 (0)