useEffect()
↔ Hook to run Effect in FC at specific stage of Component Lifecycle, set by Deps Array
Deps Array as 2nd Argument to useEffect()
, to control when Effect runs during Component Lifecycle
Cleanup Function
function call on Unmount, via return function from useEffect()
Run [Effect](effect) once **onMount**
call useEffect()
with empty Deps Array
Run [Effect](effect) once **onMount** + [Cleanup](cleanup-function)
call useEffect()
with empty Deps Array & return Cleanup Function
Run [Effect](effect) on specific renders
call useEffect()
with relevant data in Deps Array
useEffect(() => { document.title = title
}, [title] )
Run [Effect](effect) + [Cleanup](cleanup-function) on **specific renders**
call useEffect()
with property in Deps Array & Cleanup Function
Run Effect
Sync
before repaint DOM API
variables need to be added to [deps] if
declared inside fn or received as props
imported variables do not need to be added to deps
References
Cleanup Function
↔ function call on Unmount, via return function fromuseEffect()
Run [
Effect](effect) once **onMount**
↔ calluseEffect()
with empty Deps ArrayRun [
Effect](effect) once **onMount** + [
Cleanup](cleanup-function)
↔ calluseEffect()
with empty Deps Array & return Cleanup FunctionRun [
Effect](effect) on specific renders
↔ calluseEffect()
with relevant data in Deps Array
useEffect(() => { document.title = title
}, [title] )
Run [
Effect](effect) + [
Cleanup](cleanup-function) on **specific renders**
↔ calluseEffect()
with property in Deps Array & Cleanup FunctionuseLayoutEffect()
↔ Hook variant ofuseEffect()
, to call Effect as soon as DOM API generated BEFORE UI repaints to DOM APIRun [**_
useEffect()_**](useeffect) only [
Cleanup](cleanup-function) for [
Unmount](unmount)
↔ double Arrow Function to return Cleanup Function
useEffect(() => () => CLEANUP(),
[] )