Skip to content

Commit e83da8a

Browse files
authoredMar 26, 2021
Merge pull request #1286 from TQjona/master
refactor: remove unneeded object
2 parents ffbe35e + 740c4e3 commit e83da8a

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed
 

‎src/useTranslation.js

+7-9
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,9 @@ export function useTranslation(ns, props = {}) {
4040

4141
// binding t function to namespace (acts also as rerender trigger)
4242
function getT() {
43-
return {
44-
t: i18n.getFixedT(null, i18nOptions.nsMode === 'fallback' ? namespaces : namespaces[0]),
45-
};
43+
return i18n.getFixedT(null, i18nOptions.nsMode === 'fallback' ? namespaces : namespaces[0]);
4644
}
47-
const [t, setT] = useState(getT()); // seems we can't have functions as value -> wrap it in obj
45+
const [t, setT] = useState(getT);
4846

4947
const isMounted = useRef(true);
5048
useEffect(() => {
@@ -55,12 +53,12 @@ export function useTranslation(ns, props = {}) {
5553
// in side effect and do not call resetT if unmounted
5654
if (!ready && !useSuspense) {
5755
loadNamespaces(i18n, namespaces, () => {
58-
if (isMounted.current) setT(getT());
56+
if (isMounted.current) setT(getT);
5957
});
6058
}
6159

6260
function boundReset() {
63-
if (isMounted.current) setT(getT());
61+
if (isMounted.current) setT(getT);
6462
}
6563

6664
// bind events to trigger change, like languageChanged
@@ -81,13 +79,13 @@ export function useTranslation(ns, props = {}) {
8179
const isInitial = useRef(true);
8280
useEffect(() => {
8381
if (isMounted.current && !isInitial.current) {
84-
setT(getT());
82+
setT(getT);
8583
}
8684
isInitial.current = false;
8785
}, [i18n]); // re-run when i18n instance was replaced
8886

89-
const ret = [t.t, i18n, ready];
90-
ret.t = t.t;
87+
const ret = [t, i18n, ready];
88+
ret.t = t;
9189
ret.i18n = i18n;
9290
ret.ready = ready;
9391

0 commit comments

Comments
 (0)
Please sign in to comment.