refactor: simplify I18n component by removing loading state and handling locale setting directly

pull/22810/head
twwu 10 months ago
parent c362643fd6
commit b6ade4d1e3

@ -1,11 +1,10 @@
'use client' 'use client'
import type { FC } from 'react' import type { FC } from 'react'
import React, { useEffect, useState } from 'react' import React, { useEffect } from 'react'
import I18NContext from '@/context/i18n' import I18NContext from '@/context/i18n'
import type { Locale } from '@/i18n' import type { Locale } from '@/i18n'
import { setLocaleOnClient } from '@/i18n' import { setLocaleOnClient } from '@/i18n'
import Loading from './base/loading'
export type II18nProps = { export type II18nProps = {
locale: Locale locale: Locale
@ -15,17 +14,10 @@ const I18n: FC<II18nProps> = ({
locale, locale,
children, children,
}) => { }) => {
const [loading, setLoading] = useState(true)
useEffect(() => { useEffect(() => {
setLocaleOnClient(locale, false).then(() => { setLocaleOnClient(locale, false)
setLoading(false)
})
}, [locale]) }, [locale])
if (loading)
return <div className='flex h-screen w-screen items-center justify-center'><Loading type='app' /></div>
return ( return (
<I18NContext.Provider value={{ <I18NContext.Provider value={{
locale, locale,

Loading…
Cancel
Save