* cache full rendering * still not working with gzip * progress progress progress * smaller * hacky progress * small fixes * wip * lock file * wip * wip * package-lock updates * wip * search DOM in lowercase * simplify * with instrument * improve test coverage * mutateCheeriobodyByRequest * fix * remove renderContentCacheByContex * disable render caching in sync-search * diables things in github/github link checker * gzip lru * tidying up * updated * correct tests * fix: move userLanguage to LanguagesContext * Revert "fix: move userLanguage to LanguagesContext" This reverts commit d7c05d958c71eaad496eb46764eb845d80b866ca. * contexts ftw * fixed rendering tests * oops for got new file * nits addressed Co-authored-by: Mike Surowiec <mikesurowiec@users.noreply.github.com>
27 lines
586 B
TypeScript
27 lines
586 B
TypeScript
import { createContext, useContext } from 'react'
|
|
|
|
type LanguageItem = {
|
|
name: string
|
|
nativeName?: string
|
|
code: string
|
|
hreflang: string
|
|
wip?: boolean
|
|
}
|
|
|
|
export type LanguagesContextT = {
|
|
languages: Record<string, LanguageItem>
|
|
userLanguage: string
|
|
}
|
|
|
|
export const LanguagesContext = createContext<LanguagesContextT | null>(null)
|
|
|
|
export const useLanguages = (): LanguagesContextT => {
|
|
const context = useContext(LanguagesContext)
|
|
|
|
if (!context) {
|
|
throw new Error('"useLanguagesContext" may only be used inside "LanguagesContext.Provider"')
|
|
}
|
|
|
|
return context
|
|
}
|