fix: render GlobalAudioPlayer only on client side

This commit is contained in:
Hossein Mehrabi 2023-08-21 15:47:27 +03:30
parent 6b4a81ce11
commit 5fcaef4da6
No known key found for this signature in database
GPG Key ID: 45C04964191AFAA1
2 changed files with 16 additions and 2 deletions

View File

@ -1,3 +1,4 @@
import { GlobalAudioPlayer } from '@/components/GlobalAudioPlayer'
import { ProgressBar } from '@/components/ProgressBar/ProgressBar'
import { uiConfigs } from '@/configs/ui.configs'
import { SearchBarProvider } from '@/context/searchbar.context'
@ -8,7 +9,7 @@ import type { AppProps } from 'next/app'
import Head from 'next/head'
import { ReactNode } from 'react'
import { LSDThemeProvider } from '../containers/LSDThemeProvider'
import { GlobalAudioPlayer } from '@/components/GlobalAudioPlayer'
import { useHydrated } from '../utils/useHydrated.util'
type NextLayoutComponentType<P = {}> = NextComponentType<
NextPageContext,
@ -23,6 +24,8 @@ type AppLayoutProps<P = {}> = AppProps & {
}
export default function App({ Component, pageProps }: AppLayoutProps) {
const hydrated = useHydrated()
const getLayout =
Component.getLayout ||
((page: ReactNode) => <DefaultLayout>{page}</DefaultLayout>)
@ -95,7 +98,7 @@ export default function App({ Component, pageProps }: AppLayoutProps) {
<SearchBarProvider>
{getLayout(<Component {...pageProps} />)}
</SearchBarProvider>
<GlobalAudioPlayer />
{hydrated && <GlobalAudioPlayer />}
</LSDThemeProvider>
)
}

View File

@ -0,0 +1,11 @@
import { useEffect, useState } from 'react'
export const useHydrated = () => {
const [value, setValue] = useState(false)
useEffect(() => {
setValue(true)
}, [])
return value
}