Next.js Discord

Discord Forum

Singleton with i18Next

Unanswered
Purple Martin posted this in #help-forum
Open in Discord
Avatar
Purple MartinOP
in the documentation for i18next with app router, we can see the following piece of code:

async function initI18next(lng: string, ns: string) {
  // on server side we create a new instance for each render, because during compilation everything seems to be executed in parallel
  const i18nInstance = createInstance();
  await i18nInstance
    .use(initReactI18next)
    .use(
      resourcesToBackend(
        (language: string, namespace: string) =>
          import(`./locales/${language}/${namespace}.json`),
      ),
    )
    .init(getOptions(lng, ns));

  return i18nInstance;
}


Why do we have to create a new instance on every render ? Could we just create a singleton ?

0 Replies