fix: fixed the loading issue by adding a suspense (#510)

This commit is contained in:
Linkie Link 2023-09-27 14:57:10 +02:00 committed by GitHub
parent 4630426ae7
commit 5bbb59d5dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 15 deletions

View File

@ -35,18 +35,21 @@ export default function useLocalStorage<T>(key: string, defaultValue: T): [T, (v
}
}, [updateValue])
const setValue = useCallback((value: T) => {
try {
updateValue(value)
const setValue = useCallback(
(value: T) => {
try {
updateValue(value)
localStorage.setItem(keyRef.current, JSON.stringify(value))
if (typeof window !== 'undefined') {
window.dispatchEvent(new StorageEvent('storage', { key: keyRef.current }))
localStorage.setItem(keyRef.current, JSON.stringify(value))
if (typeof window !== 'undefined') {
window.dispatchEvent(new StorageEvent('storage', { key: keyRef.current }))
}
} catch (e) {
console.error(e)
}
} catch (e) {
console.error(e)
}
}, [])
},
[updateValue],
)
return [value, setValue]
}

View File

@ -1,12 +1,12 @@
import classNames from 'classnames'
import { isMobile } from 'react-device-detect'
import { useLocation } from 'react-router-dom'
import { Suspense } from 'react'
import AccountDetails from 'components/Account/AccountDetails'
import Background from 'components/Background'
import Footer from 'components/Footer'
import DesktopHeader from 'components/Header/DesktopHeader'
import MigrationBanner from 'components/MigrationBanner'
import ModalsContainer from 'components/Modals/ModalsContainer'
import PageMetadata from 'components/PageMetadata'
import Toaster from 'components/Toaster'
@ -65,10 +65,11 @@ export default function Layout({ children }: { children: React.ReactNode }) {
isMobile && 'items-start',
)}
>
<PageContainer focusComponent={focusComponent} fullWidth={isFullWidth}>
{children}
</PageContainer>
<Suspense>
<PageContainer focusComponent={focusComponent} fullWidth={isFullWidth}>
{children}
</PageContainer>
</Suspense>
<AccountDetails />
</main>
<Footer />