--- createdAt: 2024-08-11 updatedAt: 2025-06-29 title: useI18n Hook Documentation | react-intlayer description: Learn how to use the useI18n hook in the react-intlayer package keywords: - useI18n - i18n - translation - dictionary - Intlayer - internationalisation - documentation - Next.js - JavaScript - React slugs: - doc - packages - react-intlayer - useI18n history: - version: 6.0.0 date: 2025-06-29 changes: Initial writing of `useI18n` hook documentation --- # React Integration: `useI18n` Hook Documentation This section provides detailed guidance on how to use the `useI18n` hook within React applications, enabling efficient content localisation. ## Importing `useI18n` in React The `useI18n` hook can be imported and integrated into React applications according to the context as follows: - **Client Components:** ```typescript codeFormat="typescript" import { useI18n } from "react-intlayer"; // Use in client-side React components ``` ```javascript codeFormat="esm" import { useI18n } from "react-intlayer"; // Use in client-side React components ``` ```javascript codeFormat="commonjs" const { useI18n } = require("react-intlayer"); // Use in client-side React components ``` - **Server Components:** ```typescript codeFormat="commonjs" import { useI18n } from "react-intlayer/server"; // Use in server-side React components ``` ```javascript codeFormat="esm" import { useI18n } from "react-intlayer/server"; // Use in server-side React components ``` ```javascript codeFormat="commonjs" const { useI18n } = require("react-intlayer/server"); // Use in server-side React components ``` ## Parameters This hook accepts two parameters: 1. **`namespace`**: A dictionary namespace to scope the translation keys. 2. **`locale`** (optional): The desired locale. If not specified, the context's locale will be used as default. ## Dictionary All dictionary keys must be declared within content declaration files to enhance type safety and prevent errors. [Configuration instructions can be found here](https://github.com/aymericzip/intlayer/blob/main/docs/docs/{{locale}}/dictionary/get_started.md). ## Usage Examples in React Examples of using the `useI18n` hook within React components: ```tsx fileName="src/App.tsx" codeFormat="typescript" import type { FC } from "react"; import { ClientComponentExample, ServerComponentExample } from "@components"; import { IntlayerProvider } from "react-intlayer"; import { useI18n, IntlayerServerProvider } from "react-intlayer/server"; import { Locales } from "intlayer"; const App: FC<{ locale: Locales }> = ({ locale }) => { const t = useI18n("home-page", locale); return ( <>
{t("introduction")}
{t("introduction")}
{t("introduction")}
{t("description")}
{/* Display the description */}{t("description")}
{/* Display the description */}{t("description")}
{/* Display the description */}{t("description")}
{/* Display the description */}{t("description")}
{/* Display the description */}{t("description")}