Skip to content

Commit ba0acb6

Browse files
committed
fix: πŸ› fix TypeScript typings for usePromise()
1 parent aad368b commit ba0acb6

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

β€Žsrc/usePromise.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
import {useCallback} from 'react';
22
import useRefMounted from './useRefMounted';
33

4-
export type UsePromise = () => <T>(promise: Promise<T>) => Promise<T>;
4+
export type UsePromise = <T>() => (promise: Promise<T>) => Promise<T>;
55

66
const usePromise: UsePromise = () => {
77
const refMounted = useRefMounted();
8-
return useCallback(<T>(promise: Promise<T>): Promise<T> =>
9-
new Promise<T>((resolve, reject) => {
10-
promise.then(value => {
8+
return useCallback((promise: Promise<any>) =>
9+
new Promise<any>((resolve, reject) => {
10+
const onValue = value => {
1111
if (refMounted.current) {
1212
resolve(value);
1313
}
14-
}, error => {
14+
};
15+
const onError = error => {
1516
if (refMounted.current) {
1617
reject(error);
1718
}
18-
})
19+
};
20+
promise.then(onValue, onError)
1921
}), []);
2022
};
2123

0 commit comments

Comments
Β (0)