Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/next/lib/hooks/is-browser.ts
1453 views
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