-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1007 from woocommerce/fix/1002-1003-1004-verifica…
…tion-code Fix issues and react warnings for verification code components
- Loading branch information
Showing
4 changed files
with
75 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { useEffect, useCallback, useRef } from '@wordpress/element'; | ||
|
||
/** | ||
* Returns a function to check whether the caller component is mounted or unmounted. | ||
* Usually, it's used to avoid the warning - Can't perform a React state update on an unmounted component. | ||
* | ||
* @return {() => boolean} A function returns a boolean that indicates the caller component is mounted or unmounted. | ||
*/ | ||
export default function useIsMounted() { | ||
const mountedRef = useRef( false ); | ||
useEffect( () => { | ||
mountedRef.current = true; | ||
return () => { | ||
mountedRef.current = false; | ||
}; | ||
}, [] ); | ||
return useCallback( () => mountedRef.current, [] ); | ||
} |