import React, { useEffect, useState } from "react"; import type { ReactNode } from "react"; type ClientOnlyProps = { children: ReactNode; fallback?: () => JSX.Element | null; }; const ClientOnly = ({ children, fallback }: ClientOnlyProps) => { const [isMounted, setMounted] = useState(false); useEffect(() => { setMounted(true); }, []); if (typeof window === "undefined") { return fallback ? fallback() : null; } if (isMounted) { return children; } return fallback ? fallback() : null; }; export const withClientOnly = ( Component: React.ComponentType, fallback?: () => JSX.Element | null ): React.ComponentType => { return (props: any) => ( ); }; export default ClientOnly;