-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(@fluent/react) Add changeLocales and currentLocales on provider #501
base: main
Are you sure you want to change the base?
Conversation
changeLocales: (_changeLocales: string[]) => undefined as void, | ||
currentLocales: [] as string[], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we have a setter and a reader, maybe we could call they as locales
and setLocales
?
props.changeLocales(locales); | ||
setLocales(locales); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There aren't any check if the prop.changeLocales
was succeeded before to call setLocales
. Maybe we could return a bool on changeLocales
? Or use await props.changeLocales(locales)
in order to fail on except?
@@ -5,9 +5,9 @@ import { ReactLocalization } from "./localization"; | |||
/* | |||
* The `useLocalization` hook returns the FluentContext | |||
*/ | |||
type useLocalization = () => { l10n: ReactLocalization } | |||
type useLocalization = () => { l10n: ReactLocalization, changeLocales: (locales: string[]) => void, currentLocales: string[] } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm writing the type (locales: string[]) => void
2~3 times. Maybe we could to name this type and export/import from somewhere?
Closes this issue: #500
This PR aims to add on
useLocalization
a function to change the current locale,changeLocales
. So on a nested component will can to updates the locale. It's useful for a "choice language" selector.In addition to returning
changeLocales
onuseLocalization
, I also added to returncurrentLocales
, in order to avoid two sources of truth. So a "choice language" selector will need just to read the current language from the provider.I also updated the example adding the component "choice language".