Course contentsShow
← React
Lesson 336 of 2,39610. useState BasicsFree lesson

State Updates Trigger Re-renders

Understanding that calling a state setter schedules a component re-render.

State Updates Trigger Re-renders

What you'll learn: How calling a state setter function causes React to re-render your component with the new value.

The Automatic Update Cycle

When you call a state setter function (like setCount), you're not just changing a variable — you're telling React, "Hey, something important changed. You need to update what's on the screen." React responds by scheduling a re-render of that component.

Here's the flow:

  1. User clicks a button (or some event happens)
  2. Your event handler calls setCount(5)
  3. React schedules a re-render
  4. Your component function runs again from top to bottom
  5. useState returns the new value (5) this time
  6. React updates the DOM to reflect the new output

Why This Matters

This automatic re-rendering is React's superpower. You don't need to manually update the DOM or figure out what changed. You just set the new state value, and React handles the rest.

Think of it like ordering food at a restaurant: you tell the waiter what you want (call the setter), and the kitchen automatically prepares and delivers it (React re-renders). You don't walk into the kitchen yourself.

The Key Mechanism

Every time a setter is called, React treats it as a signal that the component's output might be different now. Since useState returns a new value on the next render, any JSX that depends on that value will automatically show the updated content.

Key Takeaway: Calling a state setter function schedules your component to re-render, causing useState to return the new value and React to update what's displayed on screen.