File tree 3 files changed +32
-1
lines changed
3 files changed +32
-1
lines changed Original file line number Diff line number Diff line change 111
111
- [ ` useMountedState ` ] ( ./docs/useMountedState.md ) &mdash ; track if component is mounted.
112
112
- [ ` usePromise ` ] ( ./docs/usePromise.md ) &mdash ; resolves promise only while component is mounted.
113
113
- [ ` useLogger ` ] ( ./docs/useLogger.md ) &mdash ; logs in console as component goes through life-cycles.
114
- - [ ` useMount ` ] ( ./docs/useMount.md ) &mdash ; calls ` mount ` callbacks .
114
+ - [ ` useMount ` ] ( ./docs/useMount.md ) and [ ` useUnmountPromise ` ] ( ./docs/useUnmountPromise.md ) &mdash ; tracks if component is mounted .
115
115
- [ ` useUnmount ` ] ( ./docs/useUnmount.md ) &mdash ; calls ` unmount ` callbacks.
116
116
- [ ` useUpdateEffect ` ] ( ./docs/useUpdateEffect.md ) &mdash ; run an ` effect ` only on updates.
117
117
- [ ` useIsomorphicLayoutEffect ` ] ( ./docs/useIsomorphicLayoutEffect.md ) &mdash ; ` useLayoutEffect ` that does not show warning when server-side rendering.
Original file line number Diff line number Diff line change
1
+ # ` useUnmountPromise `
2
+
3
+ A life-cycle hook that provides a higher order promise that does not resolve if component un-mounts.
4
+
5
+
6
+ ## Usage
7
+
8
+ ``` ts
9
+ import useUnmountPromise from ' react-use/lib/useUnmountPromise' ;
10
+
11
+ const Demo = () => {
12
+ const mounted = useUnmountPromise ();
13
+ useEffect (async () => {
14
+ await mounted (someFunction ()); // Will not resolve if component un-mounts.
15
+ });
16
+ };
17
+ ```
18
+
19
+
20
+ ## Reference
21
+
22
+ ``` ts
23
+ const mounted = useUnmountPromise ();
24
+
25
+ mounted (promise );
26
+ mounted (promise , onError );
27
+ ```
28
+
29
+ - ` onError ` &mdash ; if promise rejects after the component is unmounted, ` onError `
30
+ callback is called with the error.
Original file line number Diff line number Diff line change @@ -85,6 +85,7 @@ export { default as useTitle } from './useTitle';
85
85
export { default as useToggle } from './useToggle' ;
86
86
export { default as useTween } from './useTween' ;
87
87
export { default as useUnmount } from './useUnmount' ;
88
+ export { default as useUnmountPromise } from './useUnmountPromise' ;
88
89
export { default as useUpdate } from './useUpdate' ;
89
90
export { default as useUpdateEffect } from './useUpdateEffect' ;
90
91
export { default as useUpsert } from './useUpsert' ;
You can’t perform that action at this time.
0 commit comments