sanity
Version:
Sanity is a real-time content infrastructure with a scalable, hosted backend featuring a Graph Oriented Query Language (GROQ), asset pipelines and fast edge caches
29 lines (24 loc) • 584 B
text/typescript
import {useContext} from 'react'
import {LocaleContext, type LocaleContextValue} from '../LocaleContext'
import {type Locale} from '../types'
/**
* Returns the currently active locale
*
* @public
*/
export function useCurrentLocale(): Locale {
return useLocale().currentLocale
}
/**
* @hidden
* @internal
*/
export function useLocale(): LocaleContextValue {
const context = useContext(LocaleContext)
if (!context) {
throw new Error(
'Sanity LocaleContext value missing. Is this hook being used outside LocaleContext.Provider?',
)
}
return context
}