Course contentsShow
← React
Lesson 530 of 2,39615. useEffect FundamentalsFree lesson

Effects Run After Every Render (By Default)

Understand the default behavior: effects execute after the initial render and every subsequent update.

Effects Run After Every Render (By Default)

You'll learn: Why your useEffect code executes not just once, but after every single render by default.

The Default Behavior

When you write a useEffect hook without any special configuration, React runs your effect function after the initial render and then again after every subsequent re-render. This means if your component re-renders 10 times, your effect runs 10 times.

This happens because React assumes your effect needs to stay synchronized with the current props and state. Without any way to know what data your effect depends on, React plays it safe and re-runs it every time.

Why This Matters

Imagine you have a component that updates a page title based on a count state variable. Every time count changes and your component re-renders, the effect runs again to update the title with the latest value. That's exactly what you want!

But consider this: if your component re-renders for any reason (a parent re-renders, a different piece of state changes, etc.), that same effect will run again — even if count hasn't changed at all.

The Kitchen Timer Analogy

Think of it like a kitchen timer that resets after every dish you prepare. You finish making a salad? Timer runs. You stir the soup? Timer runs again. Even if the soup doesn't need timing, the timer fires anyway because it doesn't know which dishes actually need it.

This default behavior is intentional but can be wasteful. That's why React provides dependency arrays (which you'll learn about next) to control when effects should re-run.

Key Takeaway: By default, useEffect runs after every render (initial and updates), ensuring effects stay synchronized but potentially executing more often than necessary.