import {ref, Ref, UnwrapRef} from 'vue'; import useAsync, {AsyncState} from './useAsync'; import useState from "./useState"; export type AsyncStateRetry = AsyncState & { retry(): void; }; export default function useAsyncRetry(fn: () => Promise, deps: any[] = []) : AsyncStateRetry { const [attempt, setAttempt] = useState(0); const state = useAsync(fn, [...deps, attempt]) as AsyncStateRetry; state.retry = () => { if (state.loading) { if (process.env.NODE_ENV === 'development') { console.log( 'You are calling useAsyncRetry hook retry() method while loading in progress, this is a no-op.' ); } return; } setAttempt((currentAttempt) => currentAttempt + 1); }; return state; };