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/frontend/app-framework/delayed-render-hook.ts
Views: 687
1
import { useState } from "react";
2
import { useAsyncEffect } from "use-async-effect";
3
import { delay } from "awaiting";
4
5
export default function useDelayedRender(delay_ms: number) {
6
const [render, setRender] = useState<boolean>(delay_ms <= 0);
7
useAsyncEffect(async (is_mounted) => {
8
if (delay_ms == 0) return;
9
await delay(delay_ms);
10
if (!is_mounted()) return;
11
setRender(true);
12
}, []);
13
return render;
14
}
15
16