1import {useEffect, useRef} from 'react'; 2 3export default function (msg?: string, deps: any[] = []) { 4 const idRef = useRef<number>(); 5 useEffect(() => { 6 idRef.current = Math.random(); 7 console.log('Mount', msg ?? '', idRef.current); 8 return () => { 9 console.log('Unmount', msg ?? '', idRef.current); 10 }; 11 }, []); 12 13 useEffect(() => { 14 if (deps?.length !== 0) { 15 console.log('State Change', msg ?? '', idRef.current); 16 } 17 }, deps); 18 19 useEffect(() => { 20 idRef.current && console.log('Rerender: ', msg ?? '', idRef.current); 21 }); 22} 23