|
|||||
Lesson 4Class component and Functional component and the useEffect hookWhat does useEffect do? By using this Hook, you tell React that your component needs to do something after render. Why is useEffect called inside a component? Placing useEffect inside the component lets us access the count state variable (or any props) right from the effect. We don’t need a special API to read it — it’s already in the function scope. Hooks embrace JavaScript closures and avoid introducing React-specific APIs where JavaScript already provides a solution. Does useEffect run after every render? Yes! By default, it runs both after the first render and after every update. Instead of thinking in terms of “mounting” and “updating”, you might find it easier to think that effects happen “after render”. React guarantees the DOM has been updated by the time it runs the effects. Class Component with the useEffect hook Functional Component with the useEffect hook |
|||||
|