Skip to content

Instantly share code, notes, and snippets.

@guillermodlpa
Created June 9, 2022 10:11
Show Gist options
  • Save guillermodlpa/8666faadfc5a839936c435a4683ac071 to your computer and use it in GitHub Desktop.
Save guillermodlpa/8666faadfc5a839936c435a4683ac071 to your computer and use it in GitHub Desktop.
NoSsr React component with TypeScript
import { useEffect, useState } from 'react';
export default function NoSsr({ children }: { children: React.ReactNode }) {
const [mountedState, setMountedState] = useState(false);
useEffect(() => {
setMountedState(true);
}, []);
return <>{mountedState ? children : null}</>;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment