Ask your question and get a summary of the document by referencing this page and the AI provider of your choice
Version History
- "Release of the dynamic content feature"v9.0.012/06/2026
The content of this page was translated using an AI.
See the last version of the original content in EnglishIf you have an idea for improving this documentation, please feel free to contribute by submitting a pull request on GitHub.
GitHub link to the documentationCopy doc Markdown to clipboard
Dynamic Records
A dynamic record is a content file whose identity is not a sequential index or a named variant, but an arbitrary set of key-value pairs declared in a meta field. Intlayer uses those fields as the selector at runtime, making it possible to address CMS records, user-specific copy, or any content whose keys are not known at build time.
Declaring dynamic records
Copy the code to the clipboard
import { t, type Dictionary } from "intlayer";
const dictionary = {
key: "product-copy",
meta: {
id: "prod_abc",
userId: "user_123",
},
content: {
name: t({ en: "Widget Pro", fr: "Widget Pro" }),
description: t({ en: "The best widget.", fr: "Le meilleur widget." }),
},
} satisfies Dictionary;
export default dictionary;Copy the code to the clipboard
import { t, type Dictionary } from "intlayer";
const dictionary = {
key: "product-copy",
meta: {
id: "prod_abcd",
userId: "user_123",
},
content: {
name: t({ en: "Widget Lite", fr: "Widget Lite" }),
description: t({ en: "A lighter option.", fr: "Une option plus légère." }),
},
} satisfies Dictionary;
export default dictionary;Consuming dynamic records
All meta fields are required in the selector. Omitting any field returns null and is a TypeScript error.
Copy the code to the clipboard
import { useIntlayer } from "react-intlayer";
export const ProductCopy = ({
productId,
userId,
}: {
productId: string;
userId: string;
}) => {
const content = useIntlayer("product-copy", { id: productId, userId });
// TypeScript enforces that both `id` and `userId` are provided.
if (!content) return null;
return <p>{content.description}</p>;
};With explicit locale
Copy the code to the clipboard
const content = useIntlayer("product-copy", { id: "prod_abc", userId: "user_123", locale: "fr",});Missing meta field — compile-time error
Copy the code to the clipboard
// Type error: `userId` is missingconst content = useIntlayer("product-copy", { id: "prod_abc" });Loading mode
Dynamic records are typically loaded lazily. Set importMode on the dictionary to control this:
Copy the code to the clipboard
const dictionary = {
key: "product-copy",
importMode: "fetch", // or "dynamic"
meta: { id: "prod_abc", userId: "user_123" },
content: { … },
} satisfies Dictionary;
export default dictionary;See bundle optimisation for details on static, dynamic, and fetch modes.
Typical use-cases
- Per-product marketing copy managed in a CMS
- User-specific or account-specific content
- Any content keyed by an opaque runtime ID