--- createdAt: 2025-08-23 updatedAt: 2026-09-27 priority: 5 title: useIntlayer Hook Documentation | next-intlayer description: "Use useIntlayer in Next.js to read a dictionary's localized content by key in Client and Server Components." keywords: - useIntlayer - dictionary - key - Intlayer - Internationalization - Documentation - Next.js - JavaScript - React slugs: - doc - packages - next-intlayer - useIntlayer history: - version: 9.4.0 date: 2026-08-22 changes: "Update to Next.js >= 9.4.0 architecture" - version: 8.9.0 date: 2026-05-04 changes: "Update Solid useIntlayer API usage to direct property access" - version: 5.5.10 date: 2025-06-29 changes: "Initial history" author: aymericzip --- # Next.js Integration: `useIntlayer` Hook Documentation The `useIntlayer` hook is tailored for Next.js applications to fetch and manage localized content efficiently. This documentation will focus on how to utilize the hook within Next.js projects, ensuring proper localization practices. ## Importing `useIntlayer` in Next.js Depending on whether you're working on client-side or server-side components in a Next.js application, you can import the `useIntlayer` hook as follows: - **Client Component:** ```typescript codeFormat="typescript" import { useIntlayer } from "next-intlayer"; // Used in client-side components ``` ```javascript codeFormat="esm" import { useIntlayer } from "next-intlayer"; // Used in client-side components ``` ```javascript codeFormat="commonjs" const { useIntlayer } = require("next-intlayer"); // Used in client-side components ``` - **Server Component:** ```tsx codeFormat="typescript" import { useIntlayer } from "next-intlayer/server"; // Used in server-side components ``` ```javascript codeFormat="esm" import { useIntlayer } from "next-intlayer/server"; // Used in server-side components ``` ```javascript codeFormat="commonjs" const { useIntlayer } = require("next-intlayer/server"); // Used in server-side components ``` ## Parameters 1. **`key`**: A string identifier for the dictionary key from which you want to retrieve content. 2. **`locale`** (optional): A specific locale to use. If omitted, the hook defaults to the locale set in the client or server context. ## Dictionary Files It's crucial that all content keys are defined within content declaration files to prevent runtime errors and ensure type safety. This approach also facilitates TypeScript integration for compile-time validation. Instructions for setting up content declaration files are available [here](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/dictionary/content_file.md). - [Content Declaration Files (.content.ts)](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/dictionary/content_file.md) ## Example Usage in Next.js Here's how you can implement the `useIntlayer` hook within a Next.js page to dynamically load localized content based on the application's current locale: ```tsx fileName="src/pages/[locale]/index.tsx" codeFormat={["typescript", "esm"]} import { ClientComponentExample } from "@components/ClientComponentExample"; import { ServerComponentExample } from "@components/ServerComponentExample"; import { type NextPageIntlayer } from "next-intlayer"; import { useIntlayer } from "next-intlayer"; import { IntlayerProvider } from "next-intlayer/server"; const HomePage: NextPageIntlayer = async ({ params }) => { const { locale } = await params; const content = useIntlayer("homepage", locale); return (

{content.introduction}

); }; ```
```tsx fileName="src/pages/[locale]/index.tsx" codeFormat={["typescript", "esm"]} import { ClientComponentExample } from "@components/ClientComponentExample"; import { ServerComponentExample } from "@components/ServerComponentExample"; import { type NextPageIntlayer, IntlayerClientProvider } from "next-intlayer"; import { useIntlayer, IntlayerServerProvider } from "next-intlayer/server"; const HomePage: NextPageIntlayer = async ({ params }) => { const { locale } = await params; const content = useIntlayer("homepage", locale); return ( <>

{content.introduction}

); }; ```
```tsx fileName="src/components/ClientComponentExample.tsx" codeFormat={["typescript", "esm"]} "use-client"; import type { FC } from "react"; import { useIntlayer } from "next-intlayer"; const ClientComponentExample: FC = () => { const content = useIntlayer("component-content"); return (

{content.title}

{content.description}

); }; ``` ```tsx fileName="src/components/ServerComponentExample.tsx" codeFormat={["typescript", "esm"]} import type { FC } from "react"; import { useIntlayer } from "next-intlayer/server"; const ServerComponentExample: FC = () => { const content = useIntlayer("component-content"); return (

{content.title}

{content.description}

); }; ``` ## Handling Attribute Localization To localize attributes such as `alt`, `title`, `href`, `aria-label`, etc., ensure you reference the content correctly: ```tsx {content.image.alt.value} {content.image.alt.toString()} {String(content.image.alt)} ``` ## Further Information - **Intlayer Visual Editor**: Learn how to use the visual editor for easier content management [here](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/intlayer_visual_editor.md). This documentation outlines the use of the `useIntlayer` hook specifically within Next.js environments, providing a robust solution for managing localization across your Next.js applications.