Helper hooks
useLocale()
useLocale()
retrieves the user's current language as an ISO-639 (opens in a new tab) language code.
It can be used in the descendants of <GTProvider>
.
import { useLocale } from 'gt-react'
export default function MyComponent() {
const locale = useLocale(); // e.g. 'en-US'
return (
<div>
{locale}
</div>
)
}
useDefaultLocale()
The application's default locale can be accessed in the descendants of <GTProvider>
with the useDefaultLocale()
hook.
import { useDefaultLocale } from 'gt-react'
export default function MyComponent() {
const defaultLocale = useDefaultLocale();
return (
<div>
{defaultLocale}
</div>
)
}