cal.pub0.org/packages/core/components/NoSSR.tsx

21 lines
409 B
TypeScript

import { useState, useEffect } from "react";
interface Props {
children: React.ReactNode; // React.ReactNode
fallback?: JSX.Element | null; // JSX.Element
}
const NoSSR = ({ children, fallback = null }: Props) => {
const [mounted, setMounted] = useState(false);
useEffect(() => setMounted(true), []);
if (!mounted) {
return fallback;
}
return <>{children}</>;
};
export default NoSSR;