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
|
Line | |
---|
1 | import { __assign, __spreadArrays } from "tslib";
|
---|
2 | import { useCallback, useState } from 'react';
|
---|
3 | import useAsync from './useAsync';
|
---|
4 | var 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 | };
|
---|
20 | export default useAsyncRetry;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.