Why is Suspense used twice in the React example?
See original GitHub issueI’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
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Suspense for Data Fetching (Experimental) - React
It's a mechanism for data fetching libraries to communicate to React that the data a component is reading is not ready yet. React...
Read more >A practical example of Suspense in React 18
The logic used by Suspense is literally the opposite of ErrorBoundary , so if my code is throwing an exception, because it's either...
Read more >React Suspense - Component is rendering twice sometimes ...
I'm trying the new react features like useEffect hook, lazy/suspense and react-cache and I am confused about the usage.
Read more >Using Suspense and React Query: Tutorial with examples
Suspense simplifies managing loading states in React components, supporting fallbacks in case the component hasn't finished loading yet.
Read more >Why does useEffect Run Twice in React v18.0? - Bits and Pieces
The answer is to ensure reusable state. It allows React to add and remove sections of the UI while preserving state. For example,...
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
@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)
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: