0

Using react-i18next with Suspense.

I want to use the init callback option to run an axios interceptor to ensure all requests add the correct header language.

My problem is that the init callback doesn't halt the Suspense to render its children. I thought returning a promise from init would work but it doesn't.

Is halting the Suspense to resolve possible?

My code:

i18n
  .use(Backend)
  .use(initReactI18next)
  .init(
    {
      lng: 'en',
      fallbackLng: 'en',
      debug: true,
      react: {
        wait: true,
      },
    },
    function callback() {
      // this is the place where I want to halt Suspense until my logic is done

      return new Promise((res, rej) => {
        i18nInterceptor(i18n.language);
        setTimeout(() => {
          res();
        }, 10000);
      });
    }
  );

export default i18n;
Hoetmaaiers
  • 3,413
  • 2
  • 19
  • 29

0 Answers0