mirror of
https://github.com/siv-org/siv.git
synced 2026-05-03 03:00:59 -04:00
Custom <NoSsr /> component, to move away from MUI
This commit is contained in:
25
src/_shared/NoSsr.tsx
Normal file
25
src/_shared/NoSsr.tsx
Normal file
@@ -0,0 +1,25 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
|
||||
interface NoSSRProps {
|
||||
/** The content to render on client. */
|
||||
children?: React.JSX.Element | React.JSX.Element[]
|
||||
/** Optional content to show before the component renders on client. This renders during server-side rendering (SSR). */
|
||||
onSSR?: React.FC
|
||||
}
|
||||
|
||||
const EmptySpan = () => <span />
|
||||
|
||||
export const NoSsr = (props: NoSSRProps) => {
|
||||
const { onSSR = EmptySpan, children = <EmptySpan /> } = props
|
||||
|
||||
const [isMounted, setIsMounted] = useState<boolean>(false)
|
||||
|
||||
useEffect(() => {
|
||||
setIsMounted(true)
|
||||
return () => {
|
||||
setIsMounted(false)
|
||||
}
|
||||
})
|
||||
|
||||
return isMounted ? <>{children}</> : onSSR({})
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { NoSsr } from '@mui/material'
|
||||
import { NoSsr } from 'src/_shared/NoSsr'
|
||||
|
||||
const GA_ID = 'UA-84279342-7'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user