Skip to main content

Command Palette

Search for a command to run...

How react render works?

Published
•2 min read•View as Markdown
B

Experienced Java/JavaScript full-stack developer over 6 years of extensive expertise serving key role on elite technical teams developing enterprise software for healthcare, apple ad-platform, banking, and e-commerce. Adaptable problem-solver with high levels of skill in Groovy, Java, Spring, Spring Boot, Hibernate, JavaScript, TypeScript, Angular, Node, Express, React, MongoDB, IBM DB2, Oracle, PL/SQL, Docker, Kubernetes, CI/CD pipelines, AWS, Micro-service and Agile/Scrum. Strong technical skills paired with business-savvy UI design expertise. Personable team player with experience collaborating with diverse cross-functional teams.

Render vs Reconciliation vs Commit

React updates happen in three phases:


1. Render Phase

React calls your component functions to produce a new virtual UI tree.

  • Pure calculation

  • Not visible to the user

  • Can be paused, restarted, thrown away (thanks to Fiber)


2. Reconciliation Phase

React compares:

  • old virtual DOM tree

  • new virtual DOM tree

using the diffing algorithm.

React figures out:

  • which nodes changed

  • which nodes can be reused

  • which nodes need to be deleted/added


3. Commit Phase

React applies the necessary changes to the real DOM:

  • update text

  • add nodes

  • remove nodes

  • apply styles

  • attach event listeners

    This is the only phase visible to the user.

How change detection happens in Reconciliation Phase?

Step 1 — Check if the value actually changed using Objec.is(old, new):

Examples:

oldnewObject.is resultre-render?
55true❌ No
56false✔ Yes
{a:1}same objecttrue (same reference)❌ No
{a:1}{a:1} (new obj)false✔ Yes

✔ Primitives → change detected by value
✔ Objects → change detected by reference

const [user, setUser] = useState({id:1,name:'Bikash'});
user.name = 'Jack';
setUser(user) // ❌ same reference → no render

const newUser = {…user} // spread operator creates a new copy of object user in js/ts
setUser(newUser) // ✔ new reference → render

//If you want to update name property then you could do below:
const newUser = {…user, name:'Jack'};
setUser(newUser) // ✔ new reference → render

More from this blog

Bikash Mainali

75 posts

Experienced Java/JavaScript full-stack developer with 8 years of extensive expertise serving key role on elite technical teams developing and designing software.