Menu

useEffect hook Simple and accurate explanation
📰
0

useEffect hook Simple and accurate explanation

DEV Community·Aanand·about 1 month ago
#VUculyAc
Reading 0:00
15s threshold

React has one job: 👉 Take data → show UI But real apps need more than just showing UI . You also need to: fetch data from APIs set timers store data listen to events These things are outside React’s job. So useEffect lets you run code after React updates the screen, especially for things outside React. 👉 React renders UI 👉 Then useEffect runs side work ⚠️ The part most people miss (important) useEffect is not just “run after render” It’s: “Run after render — but only when something changes (if you tell it what to watch)” The 3 real behaviors (this is where clarity comes) 1.Run every time ( default ) useEffect (() => { console . log ( " Runs after every render " ); }); Enter fullscreen mode Exit fullscreen mode 👉 No control → runs again and again 👉 Usually a bad idea 2.Run only once ( on mount ) useEffect (() => { console .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More