Create Your First Functional Component in React JS – Beginner's Guide
Traditional websites reload the entire page
whenever a user clicks a link or submits a form, which can make the experience
feel slow. Modern web applications solve this problem by updating only the
parts of the page that change.
React JS is one of the most popular JavaScript
libraries used to build these modern, fast, and interactive user interfaces. It
allows developers to create reusable components, efficiently update web pages,
and build applications that provide a smooth user experience.
Developed by Facebook (now Meta) in 2013, React is now used by thousands of companies around the world, including Instagram, Netflix, WhatsApp Web, Airbnb, and many others. Its simplicity, speed, and flexibility have made it a favourite choice for both beginners and professional developers.
React applications mainly use two JavaScript libraries:
Think of it like this:
React JS is an open-source JavaScript library used for
building user interfaces (UI), especially for Single Page Applications (SPAs).
It helps developers create dynamic and interactive web applications by dividing
the user interface into small, reusable pieces called components.
Unlike traditional web development, where developers
manually update HTML whenever data changes, React automatically updates only
the parts of the page that need to change. This makes applications faster and
improves the overall user experience.
an open-source JavaScript library developed by Facebook for building fast, interactive,user interfaces.
Instead of writing the same HTML repeatedly, React allows
developers to create components, which are reusable pieces of UI.
Before React, developers often used JavaScript or jQuery to
manipulate the Document Object Model (DOM) directly. As applications became
larger, managing updates became more difficult, leading to slower performance
and more complex code.
React was created to solve these problems by:
Learning React opens the door to modern front-end
development. It is one of the most in-demand skills for web developers because
many companies use React to build professional web applications.
By learning React, you will be able to:
1. Component-Based Architecture
React applications are built using components.
A component is an independent piece of the user interface
that contains its own structure, logic, and styling.
For example, an e-commerce website may contain:
User Action
│
▼
React Component
│
▼
State / Props Change
│
▼
Virtual DOM
│
Compare Changes
│
▼
Send Updated Part to ReactDOM
ReactDOM is a package that connects React with the browser's
Document Object Model (DOM).
ReactDOM takes the components created by React and renders
them inside an HTML element.
Without ReactDOM, React components cannot be displayed in a
web browser.
Simple Definition
ReactDOM displays React components on the webpage.
React Component
│
ReactDOM.render()
│
Browser DOM
│
Visible Web Page
ReactDOM Example (React 18+)
import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App";
document.getElementById("root")
);
Step 1
Import React
import React from "react";
React allows you to create components.
Step 2
Import ReactDOM
import ReactDOM from "react-dom/client";
ReactDOM communicates with the browser.
Step 3
Import App Component
import App from "./App";
App is the main component.
Step 4
Find HTML Element
document.getElementById("root")
Finds
<div id="root"></div>
Step 5
Create Root
const root = ReactDOM.createRoot(
document.getElementById("root")
);
Creates a React Root.
Step 6
Render Component
root.render(<App />);
Displays
<App />
inside
<div id="root"></div>
Final Output
-------------------------
Welcome to React
-------------------------
App.jsx
│
React Creates Component
│
Virtual DOM
│
ReactDOM
│
Real DOM
│
Browser Screen
|
React |
ReactDOM |
|
Creates UI components |
Displays components in the browser |
|
Manages state |
Updates the browser DOM |
|
Uses Virtual DOM |
Updates the Real DOM |
|
Contains JSX logic |
Connects React with HTML |
|
Builds the interface |
Renders the interface |
Old Virtual DOM
│
New Virtual DOM
│
Compare Both
│
Find Differences
│
Update Only Changed Parts
│
ReactDOM
│
Real DOM Updated
This process makes React applications fast because it avoids
updating the entire webpage.
React and ReactDOM work together to build modern web
applications. React focuses on creating reusable components and managing how
the user interface should behave. ReactDOM takes those components and renders
them in the browser, updating only the parts of the page that change. This
combination of React + Virtual DOM + ReactDOM provides excellent
performance, cleaner code, and a better development experience for building
dynamic web applications.
Comments
Post a Comment