Skip to content

Commit

Permalink
Comment the code
Browse files Browse the repository at this point in the history
  • Loading branch information
medihack committed Mar 5, 2021
1 parent ecae71f commit b6e50de
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/useTranslation.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,15 @@ export function useTranslation(ns, props = {}) {
};
}, [namespaces.join()]); // re-run effect whenever list of namespaces changes

// t is correctly initialized by useState hook. We only neet to update it after i18n
// instance was replaced (for example in the provider).
const isInitial = useRef(true);
useEffect(() => {
if (isMounted.current && !isInitial.current) {
setT(getT());
}
isInitial.current = false;
}, [i18n]);
}, [i18n]); // re-run when i18n instance was replaced

const ret = [t.t, i18n, ready];
ret.t = t.t;
Expand Down

0 comments on commit b6e50de

Please sign in to comment.