source: imaps-frontend/node_modules/react-use/esm/useAsyncRetry.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 893 bytes
RevLine 
[d565449]1import { __assign, __spreadArrays } from "tslib";
2import { useCallback, useState } from 'react';
3import useAsync from './useAsync';
4var useAsyncRetry = function (fn, deps) {
5 if (deps === void 0) { deps = []; }
6 var _a = useState(0), attempt = _a[0], setAttempt = _a[1];
7 var state = useAsync(fn, __spreadArrays(deps, [attempt]));
8 var stateLoading = state.loading;
9 var retry = useCallback(function () {
10 if (stateLoading) {
11 if (process.env.NODE_ENV === 'development') {
12 console.log('You are calling useAsyncRetry hook retry() method while loading in progress, this is a no-op.');
13 }
14 return;
15 }
16 setAttempt(function (currentAttempt) { return currentAttempt + 1; });
17 }, __spreadArrays(deps, [stateLoading]));
18 return __assign(__assign({}, state), { retry: retry });
19};
20export default useAsyncRetry;
Note: See TracBrowser for help on using the repository browser.