source: imaps-frontend/node_modules/react-use/esm/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: 1021 bytes
Line 
1import { useMemo, useRef } from 'react';
2import useEffectOnce from './useEffectOnce';
3var useUnmountPromise = function () {
4 var refUnmounted = useRef(false);
5 useEffectOnce(function () { return function () {
6 refUnmounted.current = true;
7 }; });
8 var wrapper = useMemo(function () {
9 var race = function (promise, onError) {
10 var newPromise = new Promise(function (resolve, reject) {
11 promise.then(function (result) {
12 if (!refUnmounted.current)
13 resolve(result);
14 }, function (error) {
15 if (!refUnmounted.current)
16 reject(error);
17 else if (onError)
18 onError(error);
19 else
20 console.error('useUnmountPromise', error);
21 });
22 });
23 return newPromise;
24 };
25 return race;
26 }, []);
27 return wrapper;
28};
29export default useUnmountPromise;
Note: See TracBrowser for help on using the repository browser.