MCPcopy Create free account
hub / github.com/heygen-com/hyperframes / useToast

Function useToast

packages/studio/src/hooks/useToast.ts:5–25  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3import type { AppToast } from "../utils/studioHelpers";
4
5export function useToast() {
6 const [appToast, setAppToast] = useState<AppToast | null>(null);
7 const timerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
8
9 const showToast = useCallback((message: string, tone: AppToast["tone"] = "error") => {
10 if (timerRef.current) clearTimeout(timerRef.current);
11 setAppToast({ message, tone });
12 timerRef.current = setTimeout(() => setAppToast(null), 4000);
13 }, []);
14
15 useMountEffect(() => () => {
16 if (timerRef.current) clearTimeout(timerRef.current);
17 });
18
19 const dismissToast = useCallback(() => {
20 if (timerRef.current) clearTimeout(timerRef.current);
21 setAppToast(null);
22 }, []);
23
24 return { appToast, showToast, dismissToast };
25}

Callers 1

StudioAppFunction · 0.90

Calls 1

useMountEffectFunction · 0.90

Tested by

no test coverage detected