# gt-react: General Translation React SDK: useRegion URL: https://generaltranslation.com/ja/docs/react/api/helpers/use-region.mdx --- title: useRegion description: useRegionフックのAPIリファレンス --- {/* 自動生成: 直接編集せず、代わりに content/docs-templates/ 内のテンプレートを編集してください。 */} ## 概要 `useRegion` フックは、[`` コンテキスト](/docs/react/api/components/gtprovider) から、ユーザーが現在選択しているリージョンを取得します。 `useRegion` はクライアント側のフックであり、*クライアント側コンポーネントでのみ使用できます*。 アプリが [``](/docs/react/api/components/gtprovider) でラップされていることを確認してください。 ## リファレンス ### 戻り値 `string | undefined` — 現在有効なリージョンコード (例: `"US"`、`"CA"`) です。リージョンが設定されていない場合は `undefined` です。 *** ## 使用例 ### 基本的な使い方 ```jsx title="RegionDisplay.jsx" copy 'use client'; import { useRegion } from 'gt-react'; export default function RegionDisplay() { const region = useRegion(); // [!code highlight] return

現在のリージョン: {region ?? '未設定'}

; } ``` *** ## 注記 * ユーザーがリージョンを選択していない場合は、`undefined` が返されます。 * リージョンは、[``](/docs/react/api/components/region-selector) コンポーネントまたは [`useRegionSelector`](/docs/react/api/helpers/use-region-selector) フックで設定できます。 ## 次のステップ * ユーザーがリージョンを選択できるようにするには、[``](/docs/react/api/components/region-selector) を使用します。 * カスタムのリージョンセレクターを作成するには、[`useRegionSelector`](/docs/react/api/helpers/use-region-selector) を使用します。