Skip to content

Commit 7d2f362

Browse files
docs: added js docs for useIsMountedRef hook
1 parent 6e3548f commit 7d2f362

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

package/src/hooks/useIsMountedRef.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
import { useEffect, useRef } from 'react';
22

3+
/**
4+
* Returns mount status of component. This hook can be used for purpose of avoiding any
5+
* setState calls (within async operation) after component gets unmounted.
6+
*
7+
* @example
8+
* ```
9+
* const isMounted = useIsMountedRef();
10+
* const [dummyValue, setDummyValue] = useState(false);
11+
*
12+
* useEffect(() => {
13+
* someAsyncOperation().then(() => {
14+
* if (isMounted.current) setDummyValue(true);
15+
* })
16+
* })
17+
* ```
18+
*
19+
* @returns isMounted {Object} Mount status ref for the component.
20+
*/
321
export const useIsMountedRef = () => {
422
// Initial value has been set to true, since this hook exist only for sole purpose of
523
// avoiding any setState calls (within async operation) after component gets unmounted.

0 commit comments

Comments
 (0)