2022-04-26 11:20:00 -04:00
|
|
|
import { useEffect, useState } from 'react'
|
|
|
|
import i18n from '../../../js/i18n'
|
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
|
|
|
|
function useWaitForI18n() {
|
|
|
|
const { ready: isHookReady } = useTranslation()
|
|
|
|
const [isLocaleDataLoaded, setIsLocaleDataLoaded] = useState(false)
|
2023-11-27 06:26:06 -05:00
|
|
|
const [error, setError] = useState<Error>()
|
2022-04-26 11:20:00 -04:00
|
|
|
|
|
|
|
useEffect(() => {
|
2023-11-27 06:26:06 -05:00
|
|
|
i18n
|
|
|
|
.then(() => {
|
|
|
|
setIsLocaleDataLoaded(true)
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
setError(error)
|
|
|
|
})
|
2022-04-26 11:20:00 -04:00
|
|
|
}, [])
|
|
|
|
|
|
|
|
return {
|
|
|
|
isReady: isHookReady && isLocaleDataLoaded,
|
2023-11-27 06:26:06 -05:00
|
|
|
error,
|
2022-04-26 11:20:00 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default useWaitForI18n
|