๐Ÿ”ฅ 30 Days of Frontend - Day 1

๐Ÿ”ฅ 30 Days of Frontend - Day 1

Leader โ—3 โ—7
calendar_today ago โ€ข schedule1 min read

What Actually Happens When State Changes in React?

When state changes, many developers think:

setState() โ†’ React updates the DOM

That's a useful simplified model, but there's more happening in between.

A better mental model is:

State / Props change
        โ†“
React schedules a render
        โ†“
Component runs again
        โ†“
React reconciles the new tree
        โ†“
React commits the required DOM changes

1. State or props change

For example:

const [count, setCount] = useState(0);

setCount(count + 1);

The state update tells React that the component needs to be rendered again.

2. The component runs again

React calls the component function again using the new state:

function Counter() {
  const [count, setCount] = useState(0);

  return <button>{count}</button>;
}

This is what we commonly call a re-render.

3. React creates the new element tree

The component produces a new React element tree based on the current state and props.

React now has:

Previous tree
      โ†“
New tree

It needs to determine what actually changed.

4. React reconciles the trees

React compares the new result with the previous one.

For example:

Before: <button>0</button>
After:  <button>1</button>

React doesn't need to recreate the entire DOM.

It determines the necessary update.

5. React commits the changes

After React determines what needs to change, it commits those changes to the actual DOM.

So remember:

A re-render does NOT mean the entire DOM is recreated.

This distinction is important when thinking about React performance.

A component rendering again isn't automatically a performance problem.

Instead, ask:

Did this render produce unnecessary work?

That's where tools such as React DevTools Profiler become useful. They can help you identify expensive or unnecessary rendering before you start adding optimizations.

The mental model

Keep this simple flow in mind:

Update
  โ†“
Render
  โ†“
Reconcile
  โ†“
Commit

Understanding this flow makes React performance optimization much easier to reason about.

Before reaching for useMemo, useCallback, or React.memo, understand what is actually causing the work.

Profile first. Optimize second.

2 Comments

2 votes
1
๐Ÿ”ฅ Join developers growing publicly
Share your knowledge, build in public, and grow your developer presence with a global community.

More Posts

How I Built a React Portfolio in 7 Days That Landed โ‚น1.2L in Freelance Work

Dharanidharan - Feb 9

๐Ÿ”ฅ 30 Days of Frontend โ€” Day 2: React Reconciliation

Alaa Samy - Sep 25

5 Web Dev Pitfalls That Are Silently Killing Your Projects (With Real Fixes)

Dharanidharan - Mar 3

SolidJS 2.0 Async Data: A Deep Dive for React Devs

morellodev - Jul 16

Everyone says DeepSeek is cheaper, but I got tired of guessing the exact math. So I built a calculat

abarth23 - Apr 27
chevron_left
778 Points โ€ข 10 Badges
Alexandria, Egypt โ€ข behance.net/alaasamy12
2Posts
1Comments
2Connections

Related Jobs

View all jobs โ†’

Commenters (This Week)

1 comment
1 comment

Contribute meaningful comments to climb the leaderboard and earn badges!