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:
1.0 KB
|
Line | |
---|
1 | "use strict";
|
---|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
3 | var tslib_1 = require("tslib");
|
---|
4 | var react_1 = require("react");
|
---|
5 | var useAsync_1 = tslib_1.__importDefault(require("./useAsync"));
|
---|
6 | var useAsyncRetry = function (fn, deps) {
|
---|
7 | if (deps === void 0) { deps = []; }
|
---|
8 | var _a = react_1.useState(0), attempt = _a[0], setAttempt = _a[1];
|
---|
9 | var state = useAsync_1.default(fn, tslib_1.__spreadArrays(deps, [attempt]));
|
---|
10 | var stateLoading = state.loading;
|
---|
11 | var retry = react_1.useCallback(function () {
|
---|
12 | if (stateLoading) {
|
---|
13 | if (process.env.NODE_ENV === 'development') {
|
---|
14 | console.log('You are calling useAsyncRetry hook retry() method while loading in progress, this is a no-op.');
|
---|
15 | }
|
---|
16 | return;
|
---|
17 | }
|
---|
18 | setAttempt(function (currentAttempt) { return currentAttempt + 1; });
|
---|
19 | }, tslib_1.__spreadArrays(deps, [stateLoading]));
|
---|
20 | return tslib_1.__assign(tslib_1.__assign({}, state), { retry: retry });
|
---|
21 | };
|
---|
22 | exports.default = useAsyncRetry;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.