Professional Documents
Culture Documents
cdChapter No 6: React JS
➢ React JS
➢ React Features
➢ Hello World application
➢ Introduction to JSX
➢ Simple Application using JSX
Reference Link
• It's used for building interactive user interfaces and web applications quickly and
efficiently with significantly less code.
• React, sometimes referred to as a frontend JavaScript framework, is a JavaScript
library for building user interfaces created by Facebook.
• React is a tool for building reusable UI components and then composed these all
components together and develop your app
• React is used to build single-page applications.
• Every react application should have at least one component, which is called as root
component, which consist of other child components, so every react app is tree of
components.
• Example
• At the top there is a application, which consist of nav bar, profile, trends, feed
(which consist of tweet, like components).
• These components build separately and then merged together.
• Each component typically implemented as JavaScript class.
• When we change state of react element, we get new react element. React check this
element and child with previous one, and identify what is different and update Real
DOM to keep in sink with virtual DOM.
React Features
1. A huge amount of libraries
React combines the power of JavaScript with HTML to make it robust. In other words,
we can also call it JSX. And because it uses JavaScript, there are millions of third-
party JavaScript libraries that make web development a breeze.
2. Virtual DOM
React creates a VIRTUAL DOM in memory.
Instead of manipulating the browser's DOM directly, react creates a virtual DOM in
memory, where it does all the necessary manipulating, before making the changes in the
browser DOM.
When the page is loaded, the DOM – the object model – is created. Any changes to the
properties of individual elements make it necessary to load the entire HTML structure.
However, not with React.js.
Virtual DOM is a representation that remains loaded all the time. This means that when a
web app is updating, you have the ability to interact with it. And none of the components
would suffer.
Also, Virtual DOM speeds the loading of web pages substantially, which provides a greater
experience to the users.
3. Reusable components
The even better part is that they are totally reusable. This means that you only need to
define a component once and use it multiple times.
It speeds up the development process and also increases productivity tremendously. When
you are responsible for producing a website on a large scale, you will feel relieved to use
the same components in a different way.
For example, let’s assume that we want to create a basic menu containing two identical
buttons. Let’s start by creating one of these buttons. In a simplified version, it could look
like this:
We do not have to write this code twice to create the second button – just paste MyButton
in the component serving as the menu, as presented below.
What makes reusability a great solution is that such ready-made, once-created components
can be used whenever you want. So that the time saved on repetitive work is a resource for
completing more challenging tasks.
On the other hand, thanks to the independence of the components, the Internet is bursting
with individual components and entire frameworks ready to use.
4. Update friendly
Facilitation is clear data flow practices. In React, data always flows from the parent
component to the child files nested within it. This happens via the props object.
For example, let’s assume you want to upgrade a chat-bot on your site, in case you did not
use any ready solution, and render it to contain a specific text in an input area. Then drop:
Whether you use React-Native to develop mobile applications or just ReactJS for websites,
you will appreciate the quick refresh feature. Quick Refresh runs as soon as you save your
React file in the code editor, so you don’t have to click the refresh button every time you
want to see changes to your site.
This is extremely helpful when you are working on the details of your website. Every time
you make a small change to the code, you can immediately see the results in your browser.
Moreover, the bugs reported by the React compiler are descriptive and easy to understand,
so you don’t need to scratch your head on a bug that barely makes sense to you.
Although ReactJS was initially intended to be used exclusively inside Facebook, it was
quickly released from custody. In 2013, it was made available as open-source, and it was a
breakthrough moment.
Which solutions are based on this technology? Some examples are listed below:
React.JS History
To use React in production, you need npm which is included with Node.js.
To get an overview of what React is, you can write React code directly in HTML.
But in order to use React in production, you need npm and Node.js installed.
8 Prepared by, Mrs. Reshma Koli/Assistant Professor/Computer Engineering
Internet Programming(CSDO501)-Notes(Branch: Computer Engg/Sem:V/Revised: 2019 SH 2022
React Installation
Command is : node -v
When we install Node Js, it will automatically installed NPM (Node Package Manager)
Now go to VS Code and open created react js app (here i have created ReactTutorial)
✓ Open VS code
✓ Open folder of react app
✓ Click on index.html
✓ Right click index.html-copy path
✓ And past path in command prompt
✓ Start npm
cd reacttutorial
cd reactproject
What is JSX?
Coding JSX
JSX allows us to write HTML elements in JavaScript and place them in the DOM without
any createElement() and/or appendChild() methods.
Example:
index.js
);
Heading.jsx
function Heading(){
return <h1>React Js Using Components</h1>;
}
Para.Jsx
function Para(){
return <p>First React App</p>;
}
List.Jsx
function List(){
return (
<ol>
<li>TE COMP Div C</li>
<li>TE COMP Div D</li>
</ol>
);
}
Form.Jsx
function Form(){
return (
<form>
<label>Enter your name:
<input type="text" />
</label>
</form>
)
}
React Components in Hindi | Functional Component in React JS Hindi in 2020 #18 - YouTube