Access translation function outside of hook
See original GitHub issueI’m calling the translation from a callback (below) and keep getting the hook being used incorrectly error. I understand hooks need to be called from functional components but was wondering if translation can be called a different way.
const client = new ApolloClient({
link,
cache
});
const link = errorLink.concat(
ApolloLink.from([stateLink, AuthLink, splitlink])
);
const errorLink = onError(
({ graphQLErrors, networkError, response, operation, forward }) => {
if (graphQLErrors) {
graphQLErrors.map(({ message, path }) => {
**const [t] = useTranslation();
console.log(t(message));**
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
How to use translation i18n in React without hook?
React Hook "useTranslation" is called in function "myFunction: Middleware<{}, RootStateType>" which is neither a React function component or a ...
Read more >useTranslation (hook) - react-i18next documentation
Use the useTranslation hook inside your functional components to access the translation function or i18n instance. useTranslation params ...
Read more >A Guide to React Localization with i18next | Phrase
We access t() via react-i18next's useTranslation() react hook. The hook ensures that our components get the t() associated with our i18next instance.
Read more >Hooks FAQ - React
You can try moving that function outside of your component. In that case, the function is guaranteed to not reference any props or...
Read more >Build your own useTranslation hook with Next.js
Now the core idea of this useTranslation hooks is the t function: it receives a key and access the TRANSLATIONS object using that...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
loading is async…you need to wait for the namespace loaded
either using `i18n.init(opts, () => { /* ready here */ }``
or in a own file:
or using some event: https://www.i18next.com/overview/api#events
for 2) it is
loadNamespaces
- sorry for the typo: https://www.i18next.com/overview/api#loadnamespaces