# react-native: getLocaleFromNativeStore URL: https://generaltranslation.com/zh/docs/react-native/api/helpers/get-locale-from-native-store.mdx --- title: getLocaleFromNativeStore description: 无需 React context,即可从原生存储中读取已持久化的区域设置。 --- ## 参考 ```jsx import { getLocaleFromNativeStore } from 'gt-react-native'; const locale = getLocaleFromNativeStore(key?); // => 'en-US' | null ``` ### 参数 | 参数 | Type | 说明 | | ----- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ | | `key` | `string?` | 要从中读取的存储键。默认为 `'generaltranslation.locale'`。如果你的 [``](/docs/react-native/api/components/gtprovider) 使用了自定义的 `localeCookieName`,请在此处传入相同的值。 | ### 返回值 `string | null` — 已持久化保存的区域设置字符串;如果尚未存储任何区域设置,则为 `null`。 *** ## 用法 ```jsx copy import { getLocaleFromNativeStore } from 'gt-react-native'; const locale = getLocaleFromNativeStore(); ``` 如果你的 `GTProvider` 使用了自定义 `localeCookieName`,请传入同一个键: ```jsx copy const locale = getLocaleFromNativeStore('my-custom-key'); ``` 在区域设置变更期间,原生存储中的值可能会**与 React 状态不同步**。如需响应式更新,请改用 [`useLocale`](/docs/react-native/api/helpers/use-locale)。