2022-04-26 15:20:00 +00: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 11:26:06 +00:00
|
|
|
const [error, setError] = useState<Error>()
|
2022-04-26 15:20:00 +00:00
|
|
|
|
|
|
|
useEffect(() => {
|
2023-11-27 11:26:06 +00:00
|
|
|
i18n
|
|
|
|
.then(() => {
|
|
|
|
setIsLocaleDataLoaded(true)
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
setError(error)
|
|
|
|
})
|
2022-04-26 15:20:00 +00:00
|
|
|
}, [])
|
|
|
|
|
|
|
|
return {
|
|
|
|
isReady: isHookReady && isLocaleDataLoaded,
|
2023-11-27 11:26:06 +00:00
|
|
|
error,
|
2022-04-26 15:20:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default useWaitForI18n
|