-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Added possibility to use useTranlation returning Array or Object #714
Conversation
…t also an object. Should help #712
@kachkaev opinions about letting users choose? we could provide both options |
What if there is |
@kachkaev i want to avoid another hook. As 95% of the times you like to get some t function based on a given namespace i think this is prefered const { t } = useTranslation('ns1');
const [t] = useTranslation('ns1'); The only case you like to get the i18n instance is where you need current language or like to access the changeLanguage function. Chances are high you need t function in this component too. So your approach would be: const i18n = useI18n();
const { t } = i18n; while you could just: const { t, i18n } = useTranslation(); Beside that what we do for HOC and render prop? withI18n?!? function Extended({ i18n }) {
const { t } = i18n;
} |
Oh, I did not realise that JavaScript would allow us to return something that's both an array and an object! In this case, keeping just |
Yes, JavaScript allows to extend arrays. |
@jamuhl WDYT of updating docs too and encourage users to stick with |
I have added explicit TS tests for both usages, and I agree that the object usage should be promoted as the default (my commit reflects that) especially for js users not using types. |
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.
Very interesting - learned something new about the TS response today! I think object use should be our default.
@rosskevin @kachkaev @adrai yes...i will update the docs / samples in favor to using object spread |
published in react-i18next@10.0.1 |
https://react.i18next.com/latest/usetranslation-hook and all the other places in the docs should reflect this change |
Added possibility to use useTranlation not only expecting an array but also an object. Should help #712