diff --git a/src/useAsyncFn.ts b/src/useAsyncFn.ts index bf4b6fc0bd..b5dd7c5c38 100644 --- a/src/useAsyncFn.ts +++ b/src/useAsyncFn.ts @@ -18,17 +18,17 @@ export type AsyncState = value: T; }; -const useAsyncFn = (fn: () => Promise, deps: DependencyList = []): [AsyncState, () => void] => { +const useAsyncFn = (fn: (...args: any[]) => Promise, deps: DependencyList = []): [AsyncState, () => void] => { const [state, set] = useState>({ loading: false, }); const mounted = useRefMounted(); - const callback = useCallback(() => { + const callback = useCallback((...args) => { set({ loading: true }); - fn().then( + fn(...args).then( value => { if (mounted.current) { set({ value, loading: false });