question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Why is Suspense used twice in the React example?

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jamuhlcommented, Aug 29, 2021

@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)

0reactions
rajathgunnerscommented, Aug 29, 2021

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:

  1. Doesn’t the Suspense component not work for loadNamespaces api ??
  2. Is it because I am calling the loadNamespaces from the history.listen handler ??
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found