26 / 06 / 2022

33. useEffect

Today, I would like to introduce useEffect from REact Hooks. It accepts a function that contains imperative, possibly effectful code. We usually pair it with useState to reset the state. Mutations, subscriptions, timers, logging and other side effects are not allowed inside the main body of a function component However, by using useEffect, the function passed to it will run after the render is committed

As effects only run after every completed render, therefore, we can choose when to fire them, for example, after certain values have changed. Othe other hand, time limit can also be set to control when to run the effect, or certain conditions can be set before the effect is executed.