Created
January 13, 2022 08:16
-
-
Save longseespace/f5ab22f9264d3d40b05e722c12eb5b67 to your computer and use it in GitHub Desktop.
Debug Component Mount Lifecycle
This file contains hidden or 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
import { useMountDebug } from './useMountDebug'; | |
function SignInForm(props) { | |
useMountDebug('SignInForm'); | |
return (<div></div>) | |
} |
This file contains hidden or 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
import { useEffect } from 'react'; | |
export function useMountDebug(label = 'Component') { | |
useEffect(() => { | |
console.log(label, 'mounted'); | |
return () => { | |
console.log(label, 'unmounted'); | |
}; | |
}, []); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment