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:
567 bytes
|
Line | |
---|
1 | import { useCallback } from 'react';
|
---|
2 | import useMountedState from './useMountedState';
|
---|
3 | var usePromise = function () {
|
---|
4 | var isMounted = useMountedState();
|
---|
5 | return useCallback(function (promise) {
|
---|
6 | return new Promise(function (resolve, reject) {
|
---|
7 | var onValue = function (value) {
|
---|
8 | isMounted() && resolve(value);
|
---|
9 | };
|
---|
10 | var onError = function (error) {
|
---|
11 | isMounted() && reject(error);
|
---|
12 | };
|
---|
13 | promise.then(onValue, onError);
|
---|
14 | });
|
---|
15 | }, []);
|
---|
16 | };
|
---|
17 | export default usePromise;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.