source: imaps-frontend/node_modules/react-use/lib/useUnmountPromise.js@ d565449

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

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.2 KB
Line 
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var tslib_1 = require("tslib");
4var react_1 = require("react");
5var useEffectOnce_1 = tslib_1.__importDefault(require("./useEffectOnce"));
6var useUnmountPromise = function () {
7 var refUnmounted = react_1.useRef(false);
8 useEffectOnce_1.default(function () { return function () {
9 refUnmounted.current = true;
10 }; });
11 var wrapper = react_1.useMemo(function () {
12 var race = function (promise, onError) {
13 var newPromise = new Promise(function (resolve, reject) {
14 promise.then(function (result) {
15 if (!refUnmounted.current)
16 resolve(result);
17 }, function (error) {
18 if (!refUnmounted.current)
19 reject(error);
20 else if (onError)
21 onError(error);
22 else
23 console.error('useUnmountPromise', error);
24 });
25 });
26 return newPromise;
27 };
28 return race;
29 }, []);
30 return wrapper;
31};
32exports.default = useUnmountPromise;
Note: See TracBrowser for help on using the repository browser.