You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
925 B
36 lines
925 B
import type { ReactNode } from 'react'
|
|
import {
|
|
createContext,
|
|
useContext,
|
|
useEffect,
|
|
} from 'react'
|
|
|
|
import type { LexicsConfig, LexicsId } from './types'
|
|
|
|
import { useLexics } from './hooks'
|
|
|
|
import { getLexicFromSport } from './helpers'
|
|
|
|
type Context = ReturnType<typeof useLexics>
|
|
type Props = {
|
|
children: ReactNode,
|
|
initialLanguage?: string,
|
|
}
|
|
|
|
const LexicsContext = createContext({} as Context)
|
|
|
|
export const LexicsStore = ({ children, initialLanguage }: Props) => {
|
|
const lexics = useLexics(initialLanguage)
|
|
return <LexicsContext.Provider value={lexics}>{children}</LexicsContext.Provider>
|
|
}
|
|
|
|
export const useLexicsStore = () => useContext(LexicsContext)
|
|
|
|
export const useLexicsConfig = (config: Array<LexicsId> | LexicsConfig) => {
|
|
const { addLexicsConfig } = useLexicsStore()
|
|
|
|
useEffect(() => {
|
|
addLexicsConfig(config)
|
|
addLexicsConfig(getLexicFromSport())
|
|
}, [addLexicsConfig, config])
|
|
}
|
|
|