Skip to content

Commit 32e02b2

Browse files
committed
pass in i18n to hooks
1 parent aa71b53 commit 32e02b2

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
### next
2+
3+
- hooks: enable passing in i18n to useTranslation hook so we could wrap that with a useContext enabled hook
4+
15
### 9.0.3
26

37
- fix useSSR for hooks storing state on i18n instance and not globally [671](https://github.com/i18next/react-i18next/issues/671)

src/hooks/useTranslation.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ function loadNamespaces(i18n, ns, cb) {
2121
});
2222
}
2323

24-
export function useTranslation(ns) {
24+
export function useTranslation(ns, props = {}) {
2525
// assert we have the needed i18nInstance
26-
const i18n = getI18n();
26+
const { i18n: i18nFromProps } = props;
27+
const i18n = i18nFromProps || getI18n();
2728
if (!i18n) {
2829
warnOnce('You will need pass in an i18next instance by using i18nextReactModule');
2930
return [k => k, {}];

0 commit comments

Comments
 (0)