diff --git a/packages/next-international/src/app/client/create-i18n-provider-client.tsx b/packages/next-international/src/app/client/create-i18n-provider-client.tsx index 8f9989a..9642296 100644 --- a/packages/next-international/src/app/client/create-i18n-provider-client.tsx +++ b/packages/next-international/src/app/client/create-i18n-provider-client.tsx @@ -1,4 +1,4 @@ -import React, { Context, ReactElement, ReactNode, useCallback, useEffect, useState } from 'react'; +import React, { Context, ReactElement, ReactNode, useCallback, useEffect, useMemo, useState } from 'react'; import type { LocaleContext } from '../../types'; import type { BaseLocale, ImportedLocales } from 'international-types'; import { flattenLocale } from '../../common/flatten-locale'; @@ -32,19 +32,18 @@ export function createI18nProviderClient( loadLocale(baseLocale); }, [baseLocale, loadLocale]); + const value = useMemo( + () => ({ + localeContent: (clientLocale || baseLocale) as Locale, + fallbackLocale: fallbackLocale ? flattenLocale(fallbackLocale) : undefined, + }), + [clientLocale, baseLocale, fallbackLocale], + ); + if (!clientLocale && fallback) { return fallback; } - return ( - - {children} - - ); + return {children}; }; } diff --git a/packages/next-international/src/pages/create-i18n-provider.tsx b/packages/next-international/src/pages/create-i18n-provider.tsx index b2ae077..c970fa7 100644 --- a/packages/next-international/src/pages/create-i18n-provider.tsx +++ b/packages/next-international/src/pages/create-i18n-provider.tsx @@ -1,4 +1,4 @@ -import React, { Context, ReactElement, ReactNode, useCallback, useEffect, useRef, useState } from 'react'; +import React, { Context, ReactElement, ReactNode, useCallback, useEffect, useMemo, useRef, useState } from 'react'; import type { LocaleContext } from '../types'; import type { BaseLocale, ImportedLocales } from 'international-types'; import { useRouter } from 'next/router'; @@ -65,6 +65,14 @@ export function createI18nProvider( initialLoadRef.current = false; }, [baseLocale, loadLocale, locale]); + const value = useMemo( + () => ({ + localeContent: (clientLocale || baseLocale) as Locale, + fallbackLocale: fallbackLocale ? flattenLocale(fallbackLocale) : undefined, + }), + [clientLocale, baseLocale, fallbackLocale], + ); + if (!locale || !defaultLocale) { return error(`'i18n.defaultLocale' not defined in 'next.config.js'`); } @@ -77,15 +85,6 @@ export function createI18nProvider( return fallback; } - return ( - - {children} - - ); + return {children}; }; }