Today marks Day 1 of my React journey.
I've decided to document everything I learnβnot because I'm an expert, but because I believe sharing the learning process can help other beginners while also helping me understand concepts better.
Today's goal wasn't to build an app.
It was to answer one simple question:
Why was React created in the first place? π€
Let's dive in.
π‘ Why Was React Created?
Before React existed, developers built interactive websites by directly manipulating the browser's DOM using JavaScript or jQuery.
For example:
const heading = document.querySelector("h1");
heading.textContent = "Hello World";
This works perfectly for small applications.
But imagine building something like Facebook.
- π° News Feed
- π¬ Messages
- β€οΈ Likes
- π Notifications
- π Comments
- π₯ Friends List
Each part of the page can update independently.
As applications grow larger, manually deciding:
- Which DOM node should update
- When it should update
- What else depends on it
becomes increasingly difficult.
That's where React changed everything.
Instead of manually updating the UI, React introduced a much simpler idea:
UI = Function(State)
You describe what the UI should look like, and React figures out how to efficiently update the browser.
I think that's a really elegant way to think about building user interfaces.
π³ What Is the Real DOM?
When the browser reads your HTML, it creates a tree-like structure called the Document Object Model (DOM).
For example:
<body>
<main>
<h1>Hello</h1>
</main>
</body>
The browser sees something like this:
Document
βββ body
βββ main
βββ h1
βββ Hello
This is called the Real DOM because it's managed directly by the browser.
Whenever something changes, the browser may need to:
- π Recalculate layouts
- π¨ Repaint elements
- π₯οΈ Update the screen
These operations become expensive in large applications.
βοΈ What Is a React Element?
One thing that surprised me today was learning that React doesn't immediately create HTML elements.
When we write:
const element = React.createElement(
"h1",
{},
"Hello React"
);
React actually creates a plain JavaScript object like this:
{
type: "h1",
props: {
children: "Hello React"
}
}
This object is called a React Element.
A React Element is simply a description of what the UI should look like.
It isn't a real DOM node.
That small distinction helped me understand React much better.
π§ What Is the Virtual DOM?
The Virtual DOM is another concept I finally understood today.
It's basically a JavaScript representation of the UI that lives entirely in memory.
For example:
<div>
<h1>Hello</h1>
<p>World</p>
</div>
React internally represents it as something similar to:
{
type: "div",
children: [
{
type: "h1",
children: ["Hello"]
},
{
type: "p",
children: ["World"]
}
]
}
The important thing I learned is:
The Virtual DOM doesn't exist inside the browser. It only exists in JavaScript memory.
React compares changes in this virtual representation and updates only the parts of the Real DOM that actually changed.
That's one of the reasons React applications stay efficient.
π― What Happens During the First Render?
When React renders an application for the first time:
const root = ReactDOM.createRoot(
document.querySelector("main")
);
root.render(
React.createElement(
"h1",
{},
"Hello React"
)
);
The process looks something like this:
React Element
β
Virtual DOM
β
Real DOM
β
Browser Screen
React creates the necessary DOM nodes and finally displays them in the browser.
β¨ My Biggest Takeaway Today
Today's lesson completely changed how I thought about React.
Before today I assumed React was simply another JavaScript library.
Now I realize it's actually a different way of thinking about building user interfaces.
Instead of telling the browser how to update every single element...
React lets us describe what we want the UI to look like.
That shift in mindset is what makes React so powerful.
π What I'm Learning Next
Today's lesson covered:
- β Why React?
- β Problems React Solves
- β History of React
- β SPA vs MPA
- β React Elements
- β ReactDOM
- β Virtual DOM
Tomorrow I'll continue with:
- π Reconciliation
- β‘ Diffing Algorithm
- π¨ Render Phase
- β Commit Phase
- π§΅ React Fiber Architecture
I'll continue documenting everything I learn as I go. π
π Learning Source
I'm currently learning React through the React course by Devendra Dhote at Sheriyans Coding School. These posts are my own notes and understanding of each day's lessons, written in my own words as I continue learning.
If I misunderstand any concept, feel free to correct me in the commentsβI'm here to learn. π
π Final Thoughts
This is only Day 1, but I'm already enjoying the journey.
I'm sure there will be confusing concepts, bugs, and plenty of mistakes along the wayβbut that's part of learning.
If you're also starting React from scratch, let's learn together.
See you in Day 2! π
π¬ What was the hardest React concept for you when you started?
I'd love to hear your experience in the comments. π
If you're also learning React, consider following alongβI'll be sharing what I learn every day. You can also find me on GitHub, where I'll be sharing my projects and documenting my progress.
Thanks for reading! π
Top comments (0)