File tree Expand file tree Collapse file tree 1 file changed +13
-11
lines changed Expand file tree Collapse file tree 1 file changed +13
-11
lines changed Original file line number Diff line number Diff line change 14
14
* limitations under the License.
15
15
*/
16
16
17
- import { useRef , useEffect } from 'react' ;
17
+ import { useEffect , useRef } from 'react' ;
18
18
19
19
/**
20
- * useMountedRef returns a `react.Ref` with `ref.current` boolean defining if
21
- * the component is actually mounted.
20
+ * useMounted returns a boolean which is true if the component is actually mounted.
22
21
*/
23
-
24
22
export const useMountedRef = ( ) => {
25
- const mounted = useRef ( true ) ;
26
- useEffect ( ( ) => (
27
- ( ) => {
28
- mounted . current = false ;
29
- }
30
- ) , [ ] ) ;
31
- return mounted ;
23
+ const isMountedRef = useRef ( false ) ;
24
+
25
+ useEffect ( ( ) => {
26
+ isMountedRef . current = true ;
27
+
28
+ return ( ) => {
29
+ isMountedRef . current = false ;
30
+ } ;
31
+ } , [ ] ) ;
32
+
33
+ return isMountedRef ;
32
34
} ;
You can’t perform that action at this time.
0 commit comments