Skip to content

Instantly share code, notes, and snippets.

// useEffect hook run in mount and every state change if no dependency array is provided
useEffect(() => {
return () => {
console.log("unmounting component");
};
}, []);
// useEffect hook run in mount and every state change if no dependency array is provided
useEffect(() => {
console.log('component mount', count);
console.log('component update', count);
})
// useEffect hook run in mount if empty dependency array is provided
useEffect(() => {
console.log('component mount', count);
console.log('component update', count);
}, [])
@shailesh87
shailesh87 / UseEffectHook3.js
Last active May 22, 2021 17:26
Example of useEffect hook in all three state of lifecycle
// useEffect hook run in mount and every state change if no dependency array is provided
useEffect(() => {
console.log('component mount', count);
console.log('component update', count);
},[count])