<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Amandeep Kaur</title>
    <description>The latest articles on DEV Community by Amandeep Kaur (@amandeep_kaur_04e438bee5f).</description>
    <link>https://dev.to/amandeep_kaur_04e438bee5f</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3099252%2F2b3e196d-b6a4-4cba-b11d-5e9117d7c7ae.png</url>
      <title>DEV Community: Amandeep Kaur</title>
      <link>https://dev.to/amandeep_kaur_04e438bee5f</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/amandeep_kaur_04e438bee5f"/>
    <language>en</language>
    <item>
      <title>Why React Created Its Own Call Stack? Understanding React Fiber &amp; Reconciliation</title>
      <dc:creator>Amandeep Kaur</dc:creator>
      <pubDate>Mon, 28 Apr 2025 05:25:29 +0000</pubDate>
      <link>https://dev.to/amandeep_kaur_04e438bee5f/why-react-created-its-own-call-stack-understanding-react-fiber-reconciliation-5b0a</link>
      <guid>https://dev.to/amandeep_kaur_04e438bee5f/why-react-created-its-own-call-stack-understanding-react-fiber-reconciliation-5b0a</guid>
      <description>&lt;p&gt;&lt;strong&gt;React&lt;/strong&gt; is a JavaScript library that allows you to &lt;em&gt;create user interfaces&lt;/em&gt; for web applications.&lt;br&gt;&lt;br&gt;
The &lt;strong&gt;user interface&lt;/strong&gt; is a part of the website which is used to interact with it. It includes everything you see and touch, such as text, icons, buttons, links, forms, and as well as how things look and feel on the screen.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Create React App&lt;/strong&gt;*&lt;br&gt;&lt;br&gt;
Create React App* is a &lt;strong&gt;command-line tool&lt;/strong&gt; used to create a basic React scaffold with all necessary tools, files, and folders which lets a developer focus on code, not build tools.&lt;br&gt;&lt;br&gt;
The only pre-requisite is to install the latest LTS (recommended) version of Node.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx create-react-app my-react-app
npm start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The folder structure of the application created will look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;my-app/
├── node_modules/          # All dependencies installed via npm
├── public/                # Static assets (HTML, images, etc.)
│   └── index.html         # Main HTML file
├── src/                   # Application source code
│   ├── App.css            # Styling for App component
│   ├── App.js             # Main App component
│   ├── App.test.js        # Test file for App component
│   ├── index.css          # Global styles
│   ├── index.js           # Entry point for the app
│   └── logo.svg           # React logo
├── .gitignore             # Files to ignore in version control
├── package.json           # Project metadata and dependencies
├── README.md              # Documentation for your app
└── yarn.lock/package-lock.json # Dependency lock file
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;*&lt;em&gt;What is the basic difference between React and Angular?&lt;br&gt;&lt;br&gt;
**The basic structural difference between React JS and another frontend language i.e. Angular is that React is a library whereas Angular is a framework.&lt;br&gt;&lt;br&gt;
A *library&lt;/em&gt; is a collection of pre-written code that offers specific functionality. Developers can use a library as needed, maintaining control over the application's flow, and making it more flexible.&lt;br&gt;&lt;br&gt;
In contrast, a &lt;em&gt;framework&lt;/em&gt; is a complete structure that provides tools and guidelines for building an application. A framework is less flexible as it dictates the flow and structure of the application.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is Babel?&lt;br&gt;&lt;br&gt;
Babel&lt;/strong&gt; plays a fundamental role in React. It is a JavaScript &lt;strong&gt;compiler&lt;/strong&gt; that converts the modern (&lt;em&gt;ES6 and beyond)&lt;/em&gt; and &lt;em&gt;JSX&lt;/em&gt; into a browser-compatible version of JavaScript.&lt;br&gt;&lt;br&gt;
eg:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const htmlElement= &amp;lt;h1&amp;gt;Hello, world!&amp;lt;/h1&amp;gt;;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;is converted to&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const htmlElement = React.createElement('h1', null, 'Hello, world!');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;What is JSX?&lt;br&gt;&lt;br&gt;
JSX is&lt;/strong&gt; JavaScript XML. It looks similar to HTML but with the &lt;em&gt;power of JavaScript&lt;/em&gt;. It allows developers to write HTML code in JavaScript files.&lt;/p&gt;

&lt;p&gt;Here’s an example of a React component using &lt;strong&gt;JSX syntax&lt;/strong&gt; and &lt;strong&gt;conditional rendering&lt;/strong&gt; to display text on a webpage, toggling the content with a button click:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useState } from 'react';
function HomePage() {

  const [message, setMessage] = useState("Hello Word!")
  const toggleMessage = () =&amp;gt; {
    const newMessage = (message == "Hello World") ? "Welcome to home page" : "Hello World"
    setMessage(newMessage)
  }

  return (
    &amp;lt;div&amp;gt;
      &amp;lt;h1&amp;gt;
        {message}
      &amp;lt;/h1&amp;gt;
      &amp;lt;button onClick={toggleMessage}&amp;gt;Change Text&amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

export default HomePage;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Virtual DOM&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Virtual DOM is a &lt;strong&gt;fast, in-memory&lt;/strong&gt; copy of the original DOM, so React can quickly calculate changes before touching the real DOM.&lt;/p&gt;

&lt;p&gt;Updating a real DOM is expensive and is not efficient because changes are required to be made on the browser.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;Virtual DOM exists inside JavaScript’s memory&lt;/em&gt;&lt;/strong&gt;&lt;em&gt;, and not directly on the screen.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;DOM&lt;br&gt;&lt;br&gt;
DOM (Document Object Model)&lt;/strong&gt; is a &lt;strong&gt;tree-like structure&lt;/strong&gt; that the browser creates from your &lt;strong&gt;HTML&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;It represents your &lt;strong&gt;webpage’s content&lt;/strong&gt; (like &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;button&amp;gt;&lt;/code&gt;, etc.) in a &lt;strong&gt;format that JavaScript can read and change&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8k2pbi3lgncaw1d2x8h2.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8k2pbi3lgncaw1d2x8h2.webp" alt="Image description" width="786" height="175"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;React Fiber and Reconciliation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;React Fiber&lt;/strong&gt; was introduced in &lt;em&gt;React 16&lt;/em&gt;, primarily to improve its suitability for tasks such as &lt;em&gt;layout&lt;/em&gt; and &lt;em&gt;animations&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;To know about Fiber, let’s first learn about what is R*&lt;em&gt;econciliation.&lt;/em&gt;*&lt;/p&gt;

&lt;p&gt;React makes a tree-like structure of your complete DOM called &lt;strong&gt;Virtual DOM.&lt;/strong&gt; Virtual DOMs are &lt;em&gt;low-memory consumption trees&lt;/em&gt; which are the &lt;em&gt;representation of the real DOM&lt;/em&gt;. It acts as a middle layer between the application and the actual browser DOM, enabling efficient updates and improved performance.&lt;/p&gt;

&lt;p&gt;For every &lt;strong&gt;reactive variable&lt;/strong&gt; i.e. &lt;strong&gt;state&lt;/strong&gt; change, React &lt;strong&gt;&lt;em&gt;re-renders&lt;/em&gt;&lt;/strong&gt; the component along with its child components.&lt;/p&gt;

&lt;p&gt;React creates a Virtual DOM for the &lt;em&gt;render&lt;/em&gt; and as well as for &lt;em&gt;re-render&lt;/em&gt;,&lt;br&gt;&lt;br&gt;
before re-render React uses an algorithm called &lt;strong&gt;Reconciliation&lt;/strong&gt; to compare DOM trees to determine which part needs to be &lt;strong&gt;updated&lt;/strong&gt; for &lt;em&gt;real DOM&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;In a user interface, applying every&lt;/em&gt; &lt;strong&gt;&lt;em&gt;update&lt;/em&gt;&lt;/strong&gt; &lt;em&gt;immediately isn’t always necessary. In fact, doing so can be&lt;/em&gt; &lt;strong&gt;&lt;em&gt;inefficient&lt;/em&gt;&lt;/strong&gt;&lt;em&gt;, potentially causing frame drops and negatively impacting the user experience.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Tasks can be executed based on their &lt;strong&gt;priority&lt;/strong&gt;, with higher-priority tasks, like animations, being addressed first, while lower-priority tasks, such as updating the data store, can be handled afterward.&lt;/p&gt;

&lt;p&gt;Before React Fiber, all tasks were executed simultaneously, which increased the load on the browser and reduced the efficiency of the application. If tasks are divided into chunks and performed one by one then it can perform to its full capacity.&lt;br&gt;&lt;br&gt;
The browser performs all tasks on the &lt;strong&gt;call stack&lt;/strong&gt;, and React cannot modify the browser’s call stack algorithm for task &lt;strong&gt;scheduling&lt;/strong&gt; based on priority. Therefore &lt;strong&gt;React Fiber&lt;/strong&gt; was introduced.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;React Fiber&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;React Fiber&lt;/em&gt; is the &lt;strong&gt;re-implementation&lt;/strong&gt; of the &lt;strong&gt;Call Stack&lt;/strong&gt;, which has all the following features specifically built for React Components to perform &lt;strong&gt;scheduling&lt;/strong&gt; by allowing it to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Pause&lt;/em&gt; / &lt;em&gt;Resume&lt;/em&gt; tasks.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Assign priorities&lt;/em&gt; to different types of tasks.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Reuse&lt;/em&gt; work that has already been completed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Abort&lt;/em&gt; tasks if no longer necessary.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A &lt;strong&gt;virtual stack frame&lt;/strong&gt; refers to a unit of work in React Fiber.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvs9rahgzoje3s3fyq5td.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvs9rahgzoje3s3fyq5td.webp" alt="Image description" width="800" height="870"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What’s your experience with reading the blog? Let me know in the comments!&lt;br&gt;&lt;br&gt;
Related Blog:&lt;br&gt;&lt;br&gt;
&lt;a href="https://medium.com/@akamandeep241/virtual-dom-in-react-094877c4ad91" rel="noopener noreferrer"&gt;https://medium.com/@akamandeep241/virtual-dom-in-react-094877c4ad91&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://medium.com/@akamandeep241?source=post_page---post_author_info--80bf6c4c97f4---------------------------------------" rel="noopener noreferrer"&gt;&lt;br&gt;&lt;br&gt;
&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
