MCPcopy
hub / github.com/msgbyte/tianji / useEventWithLoading

Function useEventWithLoading

src/client/hooks/useEvent.ts:40–55  ·  view source on GitHub ↗
(
  fn: T
)

Source from the content-addressed store, hash-verified

38 * Same with useEvent but return loading state
39 */
40export function useEventWithLoading<T extends (...args: any[]) => Promise<any>>(
41 fn: T
42): [T, boolean] {
43 const [isLoading, setIsLoading] = useState(false);
44
45 const _fn = useEvent(async (...args: Parameters<T>) => {
46 setIsLoading(true);
47 try {
48 return await fn(...args);
49 } finally {
50 setIsLoading(false);
51 }
52 }) as T;
53
54 return [_fn as T, isLoading];
55}

Calls 2

useEventFunction · 0.85
fnFunction · 0.85

Tested by

no test coverage detected