Why is Suspense used twice in the React example?
I've just took a look at this example:
https://github.com/i18next/react-i18next/blob/master/example/react/src/App.js
I've noticed that Suspense is used within the Page function and the App function uses Suspense as well.
I'm just wondering why the App function needs Suspense when the Page already has it?
I've currently set my project up just like your example using XHR to load my translation files. Any documentation around using i18next-xhr-backend and Suspense would be great.
Thanks, Nick
You're right...might be i accidently added the Suspense in Page when doing some tests...will remove that asap - in the end you can have suspense where needed -> just needs be outside of the hook using function
Awesome, thanks for clarifying that.
What documentation you think of?
In the end useTranslation or any other component loading namespaces via xhr-backend if not set different will throw when not ready triggering the Suspense. So everywhere you load namespaces wrapping around you will need the Suspense component -> if you like that on App, Page, Section level is up to your need.
If you like this module don’t forget to star this repo. Make a tweet, share the word or have a look at our https://locize.com to support the devs of this project -> there are many ways to help this project :pray:
Great, I understand that now. Thanks for making i18n so easy to implement!
I am fetching namespaces for my i18next from my backend server.
I have a page route to namespaces mapping json file: pageNameSpaceMapping = { '/page1': [ns1, ns2] }
I am loading namespaces by listening to route changes using
history.listen((pathname) => i18n.loadNamespaces(pageNameSpaceMapping[pathname]) ).
I also have a Suspense component wrapped at the top of my React app.
But when I navigate to /page2 route, the loadNamespaces get called and I fetch the namespaces, the react component already gets rendered and not the Suspense fallback Component.
My doubts are:
- Doesn't the Suspense component not work for loadNamespaces api ??
- Is it because I am calling the loadNamespaces from the history.listen handler ??
@rajathgunners idk...looks like you build something completely independent of react-i18next -> so the only one able to find out what is wrong - is you...
useTranslation, withTranslation all work completely fine with the Suspense API -> loadNamespace is just a function loading namespaces (there is no connection to react at all)