# gt-next: General Translation Next.js SDK: getRegion URL: https://generaltranslation.com/zh/docs/next/api/helpers/get-region.mdx --- title: getRegion description: getRegion 服务端方法的 API 参考 --- ## 概述 `getRegion` 函数会在服务器端渲染期间,从内置的区域 cookie 中读取用户当前的区域代码。 `getRegion` 是服务端方法,只能在服务器组件中使用。 如需在客户端中使用,请参阅 [`useRegion`](/docs/next/api/helpers/use-region)。 ## 参考 ### 返回值 `Promise` — 一个 Promise,对应的结果为用户的区域代码 (例如 `"US"`、`"CA"`) ;如果未设置区域,则返回 `undefined`。 *** ## 示例 ### 基本用法 ```jsx title="RegionDisplay.jsx" copy import { getRegion } from 'gt-next/server'; export default async function RegionDisplay() { const region = await getRegion(); // [!code highlight] return

Current region: {region ?? 'Not set'}

; } ``` *** ## 注意事项 * `getRegion` 是异步函数,必须使用 `await` 等待。 * 如果用户尚未选择区域,则返回 `undefined`。 * 区域信息存储在 cookie 中,可通过 [``](/docs/next/api/components/region-selector) 组件或 [`useRegionSelector`](/docs/next/api/helpers/use-region-selector) Hook 进行设置。 ## 后续步骤 * 客户端对应的用法请参见 [`useRegion`](/docs/next/api/helpers/use-region)。 * 使用 [``](/docs/next/api/components/region-selector) 让用户选择自己的区域。