作成:2025-02-07最終更新:2025-06-29
このドキュメントをあなたの好きなAIアシスタントに参照してくださいChatGPTClaudeDeepSeekGoogle AI modeGeminiPerplexityMistralGrok
このページとあなたの好きなAIアシスタントを使ってドキュメントを要約します
このページのコンテンツはAIを使用して翻訳されました。
英語の元のコンテンツの最新バージョンを見るEdit this doc
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
Copy doc Markdown to clipboard
React統合: useDictionary フック ドキュメント
このセクションでは、Reactアプリケーション内でuseDictionaryフックを使用するための詳細なガイドを提供します。ビジュアルエディタなしでローカライズされたコンテンツを効率的に扱うことが可能です。
Reactでの使用例
以下は、ReactコンポーネントでuseDictionaryフックを使用する例です:
./ComponentExample.tsx
コードをコピー
コードをクリップボードにコピー
import type { FC } from "react";
import { useDictionary } from "react-intlayer";
import componentContent from "./component.content";
const ComponentExample: FC = () => {
const { title, content } = useDictionary(componentContent);
return (
<div>
<h1>{title}</h1>
<p>{content}</p>
</div>
);
};サーバー統合
IntlayerProvider の外で useDictionary フックを使用する場合、コンポーネントをレンダリングするときにロケールを明示的にパラメータとして渡す必要があります。
./ServerComponentExample.tsx
コードをコピー
コードをクリップボードにコピー
import type { FC } from "react";
import { useDictionary } from "react-intlayer/server";
import clientComponentExampleContent from "./component.content";
const ServerComponentExample: FC<{ locale: string }> = ({ locale }) => {
const { content } = useDictionary(clientComponentExampleContent, locale);
return (
<div>
<h1>{content.title}</h1>
<p>{content.content}</p>
</div>
);
};