Open History to see the last commit
1import { createDelayedStatus, type ShownStatus } from "@t3tools/client-runtime/delayed-status";
2import { useEffect, useState } from "react";
3
4export function useDelayedStatus<A>(key: string, value: A | null): A | null {
5 const [shown, setShown] = useState<ShownStatus<A> | null>(null);
6 const [status] = useState(() => createDelayedStatus<A>(setShown));
7 useEffect(() => () => status.dispose(), [status]);
8 useEffect(() => {
9 status.update(key, value);
10 }, [status, key, value]);
11 return shown?.key === key ? shown.value : null;
12}