mirror of https://github.com/msgbyte/tailchat
feat: 好友请求的同意拒绝取消
parent
cde2d81c5f
commit
d7e8b305f9
@ -0,0 +1,19 @@
|
|||||||
|
import type { DependencyList } from 'react';
|
||||||
|
import { showErrorToasts } from '../manager/ui';
|
||||||
|
import type { FunctionReturningPromise } from '../types';
|
||||||
|
import { useAsyncFn } from './useAsyncFn';
|
||||||
|
|
||||||
|
export function useAsyncRequest<T extends FunctionReturningPromise>(
|
||||||
|
fn: T,
|
||||||
|
deps: DependencyList = []
|
||||||
|
) {
|
||||||
|
const [{ loading }, call] = useAsyncFn(async (...args) => {
|
||||||
|
try {
|
||||||
|
await fn(...args);
|
||||||
|
} catch (err) {
|
||||||
|
showErrorToasts(err);
|
||||||
|
}
|
||||||
|
}, deps);
|
||||||
|
|
||||||
|
return [{ loading }, call] as const;
|
||||||
|
}
|
Loading…
Reference in New Issue