# gt-react: General Translation React SDK: useRegionSelector URL: https://generaltranslation.com/ja/docs/react/api/helpers/use-region-selector.mdx --- title: useRegionSelector description: useRegionSelector Hook の API リファレンス --- {/* 自動生成: 直接編集しないでください。content/docs-templates/ 内の template を編集してください。 */} ## 概要 `useRegionSelector` Hook は、カスタムのリージョンセレクター UI コンポーネントの実装に必要なデータとハンドラーを提供します。現在のリージョン、利用可能なリージョンの一覧、リージョンのメタデータ、およびリージョンまたはロケールを更新する関数を返します。 `useRegionSelector` はクライアントサイドの Hook であり、*クライアントサイドコンポーネントでのみ使用できます*。 アプリが [``](/docs/react/api/components/gtprovider) でラップされていることを確認してください。 ## リファレンス ### パラメータ オプションの設定オブジェクト: | Parameter | Type | Default | Description | | ------------------------------- | ---------- | ------- | ------------------------------------------------------------------------------------------------------------------------ | | `regions` | `string[]` | — | 表示する ISO 3166 リージョンコードの配列を指定します。省略した場合、リージョンはサポートされているロケールから推定されます。 | | `customMapping` | `object` | — | リージョンの表示名、絵文字、または関連付けられたロケールを上書きするためのオプションのマッピングです。値には、文字列 (表示名) または `name`、`emoji`、`locale` プロパティのいずれかを持つオブジェクトを指定できます。 | | `prioritizeCurrentLocaleRegion` | `boolean` | `true` | `true` の場合、現在のロケールに対応するリージョンがリスト内で優先表示されます。 | | `sortRegionsAlphabetically` | `boolean` | `true` | `true` の場合、リージョンは表示名のアルファベット順に並べ替えられます。 | ### 戻り値 以下を含むオブジェクトです。 | フィールド | 型 | 説明 | | ------------ | --------------------------------------- | -------------------------------------------------------------- | | `region` | `string \| undefined` | 現在選択されているリージョンコード。 | | `setRegion` | `(region: string \| undefined) => void` | 選択中のリージョンを更新する関数。 | | `regions` | `string[]` | 利用可能なリージョンコードの配列。 | | `regionData` | `Map` | リージョンコードを、その表示データ (`code`、`name`、`emoji`、`locale`) に対応付けた Map。 | | `locale` | `string` | 現在のロケール。 | | `setLocale` | `(locale: string) => void` | ロケールを更新する関数。 | *** ## 例 ### カスタムのリージョンセレクターを作成する ```jsx title="CustomRegionSelector.jsx" copy 'use client'; import { useRegionSelector } from 'gt-react'; export default function CustomRegionSelector() { const { region, setRegion, regions, regionData } = useRegionSelector({ // [!code highlight] customMapping: { US: { name: "United States", emoji: "🇺🇸" } }, // [!code highlight] }); // [!code highlight] return ( ); } ``` *** ## 注記 * `regions` が指定されていない場合、利用可能なリージョンは [`gt.config.json`](/docs/react/api/config/gt-config-json) で設定された対応ロケールから推定されます。 * あらかじめ用意されたリージョンセレクターを使う場合は、[``](/docs/react/api/components/region-selector) コンポーネントを使用します。 ## 次のステップ * すぐに使えるドロップダウンコンポーネントは、[``](/docs/react/api/components/region-selector)を参照してください。 * 現在のリージョンを取得するには、[`useRegion`](/docs/react/api/helpers/use-region)を参照してください。 * ロケール版については、[`useLocaleSelector`](/docs/react/api/helpers/use-locale-selector)を参照してください。