CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/next/lib/hooks/is-browser.ts
Views: 687
1
/*
2
Use this hook if you want to render with react
3
ONLY on the client.
4
5
This is much better than using process.browser,
6
since it will NOT render the thing on the server,
7
will render it on the client, and the react SSR
8
hydration will not be thrown off like it is with
9
process.browser.
10
*/
11
12
import { useEffect, useState } from "react";
13
14
export default function useIsClient(): boolean {
15
const [loaded, setLoaded] = useState<boolean>(false);
16
useEffect(() => setLoaded(true), []);
17
return loaded;
18
}
19
20