The React binding for call-site (t()) strings — subscribes to the active language and
returns a t bound to it.
Use this instead of importing t from @sheetxl/utils inside a component. The module-level
t reads a singleton, so React cannot know its value changed on a language switch: a component
calling it had to separately remember to subscribe (a bare useLanguage()), and forgetting
was invisible — the string simply froze at whatever language was active when the component
mounted. (That is not hypothetical: the Name Box tooltip shipped exactly that way.) Taking t
from this hook makes the subscription inseparable from the use — the same reason
react-i18next hands you t from useTranslation() rather than exporting it.
The returned function's identity changes when the language changes, so it is the natural
memo dependency for anything that bakes a translated string:
The React binding for call-site (
t()) strings — subscribes to the active language and returns atbound to it.Use this instead of importing
tfrom@sheetxl/utilsinside a component. The module-leveltreads a singleton, so React cannot know its value changed on a language switch: a component calling it had to separately remember to subscribe (a bareuseLanguage()), and forgetting was invisible — the string simply froze at whatever language was active when the component mounted. (That is not hypothetical: the Name Box tooltip shipped exactly that way.) Takingtfrom this hook makes the subscription inseparable from the use — the same reason react-i18next hands youtfromuseTranslation()rather than exporting it.The returned function's identity changes when the language changes, so it is the natural memo dependency for anything that bakes a translated string:
The module-level
tremains exported for non-React contexts (and is what this delegates to).