next-i18next: Text content does not match server-rendered HTML
๐ Bug Report
When a use t
function inside a component, next return to me, this error:
, have any aformation about that?
To Reproduce
Iโm using ChakraUI, and Next with typescript, inside my component file a had this code:
import Head from 'next/head'
import Image from 'next/image'
import { Inter } from 'next/font/google'
import { GetStaticProps } from 'next'
import { serverSideTranslations } from 'next-i18next/serverSideTranslations'
import { useTranslation } from 'react-i18next'
const inter = Inter({ subsets: ['latin'] })
export default function Home() {
const { t } = useTranslation('common')
return (
<>
<Head>
<title>Create Next App</title>
<meta name="description" content="Generated by create next app" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" href="/favicon.ico" />
</Head>
<main>
{t('title')}
</main>
</>
)
}
export const getStaticProps : GetStaticProps = async ({locale}) => {
const lang = {
...(await serverSideTranslations(locale ?? 'en', ["common"])),
};
return { props: { ...lang } };
}
Your Environment
- runtime version: v16.16.0
- next version:v13.2.4
- i18next version: v22.4.13
- os: Windows
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 19 (9 by maintainers)
Yes, for sure this is an issue. Forget about my comment above.
Just use the correct import:
import { useTranslation } from 'next-i18next';
You passed the arguments to the serverSideTranslations function in the wrong wayโฆ
and also remove the resourcesToBackend part here:
here a fixed fork
Hey @adrai! Sorry for bringing this up again but why do we need to import
useTranslation
fromnext-i18next
? Iโm building a component library for React and Next.js applications and Iโd like to always import fromreact-i18next
.Also, Iโve checked the code and it seems that
next-i18next
is simply re-exportingreact-i18next
, is that correct?If itโs not the wrong import statement, please provide a minimal reproducible example repository and create a new issue.