mirror of
https://github.com/johndoe6345789/workforce-pay-bill-p.git
synced 2026-04-24 13:24:57 +00:00
21 lines
702 B
TypeScript
21 lines
702 B
TypeScript
import { useEffect, useRef } from 'react'
|
|
import { useIndexedDBState } from '@/hooks/use-indexed-db-state'
|
|
import { useAppDispatch, useAppSelector } from '@/store/hooks'
|
|
import { setLocale } from '@/store/slices/uiSlice'
|
|
|
|
type Locale = 'en' | 'es' | 'fr'
|
|
|
|
export function useLocaleInit() {
|
|
const dispatch = useAppDispatch()
|
|
const reduxLocale = useAppSelector(state => state.ui.locale)
|
|
const [dbLocale] = useIndexedDBState<Locale>('app-locale', 'en')
|
|
const initialized = useRef(false)
|
|
|
|
useEffect(() => {
|
|
if (!initialized.current && dbLocale && dbLocale !== reduxLocale) {
|
|
dispatch(setLocale(dbLocale))
|
|
initialized.current = true
|
|
}
|
|
}, [dbLocale, reduxLocale, dispatch])
|
|
}
|