MCPcopy
hub / github.com/OpenPipe/OpenPipe / useHandledAsyncCallback

Function useHandledAsyncCallback

app/src/utils/hooks.ts:20–44  ·  view source on GitHub ↗
(
  callback: AsyncFunction<T, U>,
  deps: React.DependencyList,
)

Source from the content-addressed store, hash-verified

18type AsyncFunction<T extends unknown[], U> = (...args: T) => Promise<U>;
19
20export function useHandledAsyncCallback<T extends unknown[], U>(
21 callback: AsyncFunction<T, U>,
22 deps: React.DependencyList,
23) {
24 const [loading, setLoading] = useState(0);
25 const [error, setError] = useState<Error | null>(null);
26
27 const wrappedCallback = useCallback((...args: T) => {
28 setLoading((loading) => loading + 1);
29 setError(null);
30
31 callback(...args)
32 .catch((error) => {
33 setError(error as Error);
34 console.error(error);
35 })
36 .finally(() => {
37 setLoading((loading) => loading - 1);
38 });
39
40 // eslint-disable-next-line react-hooks/exhaustive-deps
41 }, deps);
42
43 return [wrappedCallback, loading > 0, error] as const;
44}
45
46interface Dimensions {
47 left: number;

Callers 15

CopiableCodeFunction · 0.90
ProjectUserTableFunction · 0.90
UpdateOpenaiApiKeyModalFunction · 0.90
RemoveOpenaiApiKeyDialogFunction · 0.90
InviteProjectUserModalFunction · 0.90
DeleteProjectDialogFunction · 0.90
RemoveProjectUserDialogFunction · 0.90
NewMonitorButtonFunction · 0.90
InitialFiltersFunction · 0.90
SecondaryFiltersFunction · 0.90
AddToDatasetModalFunction · 0.90
ExportLogsModalFunction · 0.90

Calls 2

finallyMethod · 0.45
catchMethod · 0.45

Tested by

no test coverage detected