このページとあなたの好きなAIアシスタントを使ってドキュメントを要約します
このページのコンテンツはAIを使用して翻訳されました。
英語の元のコンテンツの最新バージョンを見る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
ネスト / サブコンテンツ参照
ネストの仕組み
Intlayerでは、nest関数を使用して、別の辞書からコンテンツを参照および再利用することでネストを実現します。コンテンツを重複させる代わりに、キーを使用して既存のコンテンツモジュールを指すことができます。
ネストの設定
To use nested content in a React component, leverage the useIntlayer hook from the react-intlayer package. This hook retrieves the correct content based on the specified key. Here's an example of how to use it:
コードをクリップボードにコピー
import type { FC } from "react";
import { useIntlayer } from "react-intlayer";
const NestComponent: FC = () => {
const { fullNestedContent, partialNestedContent } = useIntlayer(
"key_of_my_second_dictionary"
);
return (
<div>
<p>Full Nested Content: {JSON.stringify(fullNestedContent)}</p>
<p>Partial Nested Value: {partialNestedContent}</p>
</div>
);
};
export default NestComponent;React Intlayerでのネストの使用
Reactコンポーネントでネストされたコンテンツを使用するには、react-intlayerパッケージのuseIntlayerフックを活用します。このフックは、指定されたキーに基づいて正しいコンテンツを取得します。以下はその使用例です:
コードをクリップボードにコピー
import type { FC } from "react";
import { useIntlayer } from "react-intlayer";
const NestComponent: FC = () => {
const { fullNestedContent, partialNestedContent } = useIntlayer(
"key_of_my_second_dictionary"
);
return (
<div>
<p>
Full Nested Content: {JSON.stringify(fullNestedContent)}
{/* 出力: {"content": "content", "subContent": {"contentNumber": 0, "contentString": "string"}} */}
</p>
<p>
Partial Nested Value: {partialNestedContent}
{/* 出力: 0 */}
</p>
</div>
);
};
export default NestComponent;追加リソース
設定や使用方法の詳細については、以下のリソースを参照してください:
これらのリソースは、さまざまな環境やフレームワークでのIntlayerのセットアップと使用方法についてさらに詳しく説明しています。