Ask your question and get a summary of the document by referencing this page and the AI provider of your choice
Version History
- "Init history"v5.5.106/29/2025
If 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
React Integration: useDictionary Hook Documentation
This section provides detailed guidance on using the useDictionary hook within React applications, enabling efficient handling of localized content without a visual editor.
Importing useDictionary in React
The useDictionary hook can be integrated into React applications by importing it based on the context:
Client Component:
Server Component:
Parameters
The hook accepts two parameters:
dictionary: A declared dictionary object containing localized content for specific keys.locale(optional): The desired locale. Defaults to the current context's locale if not specified.
Dictionary
All dictionary objects should be declared in structured content files to ensure type safety and prevent runtime errors. You can find the setup instructions here. Here's an example of content declaration:
Example Usage in React Client Component
Below is an example of how to use the useDictionary hook in a React component:
Example Usage in React Server Component
If you're using the useDictionary hook outside the IntlayerServerProvider, the locale must be explicitly provided as a parameter when rendering the component:
Notes on Attributes
Unlike integrations using visual editors, attributes like buttonTitle.value do not apply here. Instead, directly access the localized strings as declared in your content.
Additional Tips
- Type Safety: Always use
Dictionaryto define your dictionaries to ensure type safety. - Localization Updates: When updating content, ensure all locales are consistent to avoid missing translations.
This documentation focuses on the integration of the useDictionary hook, providing a streamlined approach to managing localized content without relying on visual editor functionalities.