Skip to content

Commit

Permalink
Revert "Fix/bug 1691 make returned t function identical upon second e…
Browse files Browse the repository at this point in the history
…ffect run in strict mode (#1716)"

This reverts commit f8a4e19.
  • Loading branch information
adrai committed Feb 5, 2024
1 parent 66bfb80 commit 8df58e0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 47 deletions.
15 changes: 4 additions & 11 deletions react-i18next.js
Original file line number Diff line number Diff line change
Expand Up @@ -612,12 +612,6 @@
}, [value, ignore]);
return ref.current;
};
function alwaysNewT(i18n, language, namespace, keyPrefix) {
return i18n.getFixedT(language, namespace, keyPrefix);
}
function useMemoizedT(i18n, language, namespace, keyPrefix) {
return react.useCallback(alwaysNewT(i18n, language, namespace, keyPrefix), [i18n, language, namespace, keyPrefix]);
}
function useTranslation(ns) {
let props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
const {
Expand Down Expand Up @@ -656,8 +650,9 @@
namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation'];
if (i18n.reportNamespaces.addUsedNamespaces) i18n.reportNamespaces.addUsedNamespaces(namespaces);
const ready = (i18n.isInitialized || i18n.initializedStoreOnce) && namespaces.every(n => hasLoadedNamespace(n, i18n, i18nOptions));
const memoGetT = useMemoizedT(i18n, props.lng || null, i18nOptions.nsMode === 'fallback' ? namespaces : namespaces[0], keyPrefix);
const getT = () => memoGetT;
function getT() {
return i18n.getFixedT(props.lng || null, i18nOptions.nsMode === 'fallback' ? namespaces : namespaces[0], keyPrefix);
}
const [t, setT] = react.useState(getT);
let joinedNS = namespaces.join();
if (props.lng) joinedNS = `${props.lng}${joinedNS}`;
Expand All @@ -676,9 +671,7 @@
});
} else {
loadNamespaces(i18n, namespaces, () => {
if (isMounted.current) {
setT(() => alwaysNewT(i18n, props.lng || null, i18nOptions.nsMode === 'fallback' ? namespaces : namespaces[0], keyPrefix));
}
if (isMounted.current) setT(getT);
});
}
}
Expand Down
Loading

0 comments on commit 8df58e0

Please sign in to comment.