react useEffect
// Every rerender
useEffect(() => {
console.log("I run everytime this component rerenders")
});
// onMount
useEffect(() => {
console.log("I Only run once (When the component gets mounted)")
}, []);
// Condition based
useEffect(() => {
console.log("I run everytime my condition is changed")
}, [condition]);
// Condition based with "clean up"
useEffect(() => {
console.log("I run everytime my condition is changed")
return () => {
console.log("Use this return as a 'clean up tool' (this runs before the actual code)")
}
}, [condition]);