The goal from this discussion is to solidify your understanding about useEffect after studying about it before the class and in the class.
Please discuss the following questions between you and answer them in the comment section below.
Questions:
- What is
useEffect
? - What do we mean when we say that useEffect is a hook?
- useEffect gets executed in 3 different ways, what are they? (Adding code examples would be beneficial)
Angela King
Lindokuhle Skosana
Koketso Lepulana
useEffect(() => { console.log('Component rendered!'); // This will log on every render });
Secondly, once on mount and unmount, effect will only run after initial render (on mount) and the cleanup on unmount,
e.g useEffect(() => { console.log('Name changed to:', name); }, [])
Thirdly, when dependencies change, when providing dependencies array with specific variables . effect will run after initial render and whenever the dependencies change.
e.g useEffect(() => { console.log('Name changed to:', name); }, [name])