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)
Ntokozo
Thabiso
Mpilo
If you do not provide a dependency array, the useEffect will run after every render of the component
2. Running Once on Mount
If you provide an empty dependency array [], the useEffect will run only once after the initial render (similar to componentDidMount in class components).
3.Running on Dependency Change
If you provide a dependency array with specific variables, the useEffect will run after the initial render and whenever any of the dependencies change.