Skip to content

Instantly share code, notes, and snippets.

@Eliav2
Created May 3, 2021 16:36
Show Gist options
  • Save Eliav2/00f3a6d57ac048358c3a81cca659a088 to your computer and use it in GitHub Desktop.
Save Eliav2/00f3a6d57ac048358c3a81cca659a088 to your computer and use it in GitHub Desktop.
const Basic = () => {
// log function helper
// this will help up follow the component phase cycle
const render = useRef(0);
const call = useRef(0);
const consoleState = () => `{call:${call.current},render:${render.current}}`;
const log = (...args) => console.log(...args, consoleState());
// update phase counts
call.current += 1;
useEffect(() => {
render.current += 1;
});
//logic
useEffect(() => {
log('mount has finished');
}, []);
useEffect(() => {
log('render has finished');
});
log('update call');
return <div/>;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment