Skip to content

Commit

Permalink
Cache locale dict lest child hooks always re-render (#6185)
Browse files Browse the repository at this point in the history
* Cache locale dict lest child hooks always re-render

* Update context.tsx

* fix lint

---------

Co-authored-by: Robert Snow <rsnow@adobe.com>
Co-authored-by: Robert Snow <snowystinger@gmail.com>
Co-authored-by: Yihui Liao <44729383+yihuiliao@users.noreply.github.com>
  • Loading branch information
4 people authored May 16, 2024
1 parent b294de8 commit d80999e
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions packages/@react-aria/i18n/src/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,16 @@ export function I18nProvider(props: I18nProviderProps) {
let {locale, children} = props;
let defaultLocale = useDefaultLocale();

let value: Locale = locale ? {
locale,
direction: isRTL(locale) ? 'rtl' : 'ltr'
} : defaultLocale;
let value: Locale = React.useMemo(() => {
if (!locale) {
return defaultLocale;
}

return {
locale,
direction: isRTL(locale) ? 'rtl' : 'ltr'
};
}, [defaultLocale, locale]);

return (
<I18nContext.Provider value={value}>
Expand Down

1 comment on commit d80999e

@rspbot
Copy link

@rspbot rspbot commented on d80999e May 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.