( fn: T, deps: DependencyList = [] )
| 4 | import { useAsyncFn } from './useAsyncFn'; |
| 5 | |
| 6 | export function useAsyncRequest<T extends FunctionReturningPromise>( |
| 7 | fn: T, |
| 8 | deps: DependencyList = [] |
| 9 | ) { |
| 10 | const [{ loading, value }, call] = useAsyncFn(async (...args: any[]) => { |
| 11 | try { |
| 12 | return await fn(...args); |
| 13 | } catch (err) { |
| 14 | // showErrorToasts(isDevelopment ? err : t('系统忙, 请稍后再试')); |
| 15 | showErrorToasts(err); // 暂时放开所有错误抛出,正确的做法应该是仅对于内置代码相关的逻辑显示placeholder报错 |
| 16 | console.error('[useAsyncRequest] error:', err); |
| 17 | } |
| 18 | }, deps); |
| 19 | |
| 20 | return [{ loading, value }, call as T] as const; |
| 21 | } |
no test coverage detected