Next.js Discord

Discord Forum

Singleton with i18Next

Purple Martin posted this in #help-forum
Open in Discord
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
        (language: string, namespace: string) =>
    .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