← Snippets

useMountLog Hook

Added December 27, 2020

React hook to monitor when a component mount and unmounts. Useful for debugging.

1function useMountLog(componentName) {
2 React.useEffect(() => {
3 console.warn(`useMountLog: ${componentName} Mounted`)
4 return () => {
5 console.warn(`useMountLog: Unmounted ${componentName}`)
6 }
7 }, [])
8}
9