Skip to content

Commit

Permalink
changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
adrai committed Jun 14, 2022
1 parent 47d9670 commit c8c147a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### 11.17.2

- reset t if ns changes in useTranslation [1518](https://github.com/i18next/react-i18next/pull/1518)

### 11.17.1

- Stricter typescript type for Trans components prop [1516](https://github.com/i18next/react-i18next/pull/1516)
Expand Down
16 changes: 15 additions & 1 deletion react-i18next.js
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,14 @@
return useAsParent ? React__default.createElement(useAsParent, additionalProps, content) : content;
}

var usePrevious = function usePrevious(value, ignore) {
var ref = React.useRef();
React.useEffect(function () {
ref.current = ignore ? ref.current : value;
}, [value, ignore]);
return ref.current;
};

function useTranslation(ns) {
var props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var i18nFromProps = props.i18n;
Expand Down Expand Up @@ -823,6 +831,8 @@
t = _useState2[0],
setT = _useState2[1];

var joinedNS = namespaces.join();
var previousJoinedNS = usePrevious(joinedNS);
var isMounted = React.useRef(true);
React.useEffect(function () {
var bindI18n = i18nOptions.bindI18n,
Expand All @@ -835,6 +845,10 @@
});
}

if (ready && previousJoinedNS && previousJoinedNS !== joinedNS && isMounted.current) {
setT(getT);
}

function boundReset() {
if (isMounted.current) setT(getT);
}
Expand All @@ -850,7 +864,7 @@
return i18n.store.off(e, boundReset);
});
};
}, [i18n, namespaces.join()]);
}, [i18n, joinedNS]);
var isInitial = React.useRef(true);
React.useEffect(function () {
if (isMounted.current && !isInitial.current) {
Expand Down
Loading

0 comments on commit c8c147a

Please sign in to comment.