React JS
React JS
React JS
ReactJS is a JavaScript Library created by Facebook for creating dynamic and interactive
applications and building better UI/UX design for web and mobile applications. React is an
open-source and component-based front-end library. React is responsible for the UI design.
React makes code easier to debug by dividing them into components.
Features of React:
•JSX (JavaScript Syntax Extension)
•Virtual DOM
•One-way data binding
•Performance
•Extensions
•Conditional statements
•Components
•Simplicity
JSX(JavaScript Syntax Extension):
DOM stands for Document Object Model. It is the most important part of the web as it
divides into modules and executes the code. Usually, JavaScript Frameworks updates the
whole DOM at once, which makes the web application slow. But react uses virtual DOM
which is an exact copy of real DOM. Whenever there is a modification in the web application,
the whole virtual DOM is updated first and finds the difference between real DOM and
Virtual DOM. Once it finds the difference, then DOM updates only the part that has changed
recently and everything remains the same.
One-way Data Binding:
One-way data binding, the name itself says that it is a one-direction flow. The data in
react flows only in one direction i.e. the data is transferred from top to bottom i.e. from
parent components to child components. The properties(props) in the child component
cannot return the data to its parent component but it can have communication with the
parent components to modify the states according to the provided inputs. This is the
working process of one-way data binding. This keeps everything modular and fast.
Performance: As we discussed earlier, react uses virtual DOM and updates only the modified parts.
So , this makes the DOM to run faster. DOM executes in memory so we can create separate
components which makes the DOM run faster.
5. Extension: React has many extensions that we can use to create full-fledged UI applications. It
supports mobile app development and provides server-side rendering. React is extended with Flux,
Redux, React Native, etc. which helps us to create good-looking UI.
Conditional Statements:
JSX allows us to write conditional statements. The data in the browser is displayed according to
the conditions provided inside the JSX.
Components:
React.js divides the web page into multiple components as it is component-based. Each
component is a part of the UI design which has its own logic and design as shown in
the below image. So the component logic which is written in JavaScript makes it easy
and run faster and can be reusable.
Simplicity: React.js is a component-based which makes the code reusable and React.js
uses JSX which is a combination of HTML and JavaScript. This makes code easy to
understand and easy to debug and has less code.
Simple Hello World Program in
ReactJS
To create a react application, Node.js version of at least 10 or higher need to be
installed on your system. If it is installed you can check by using the following
command in your command line.
JSX creates an element in React that gets rendered in the UI. It is transformed into JavaScript
functions by the compiler at runtime. Error handling and warnings become easier to handle
when using JSX
The above code snippet somewhat looks like HTML and it also uses a JavaScript-like variable but is
neither HTML nor JavaScript, it is JSX(JavaScript XML). With the help of JSX, we have directly
written the HTML syntax in JavaScript
Features of JSX
JSX allows us to use attributes with the HTML elements just like we do with normal HTML. But
instead of the normal naming convention of HTML, JSX uses the camelcase convention for
attributes
Conditions - if statements
Children in JSX
Consider a situation where you want to render multiple tags at a time. To do this we
need to wrap all of these tags under a parent tag and then render this parent element
to the HTML. All the subtags are called child tags or children of this parent element.
Simple Application using JSX
Components are independent and reusable bits of code. They serve the same purpose
as JavaScript functions, but work in isolation and return HTML.
Components come in two types, Class components and Function components, in this
tutorial we will concentrate on Function components
Class Component
Rendering a Component
Props
Components can be passed as props, which stands for properties.
Props are like function arguments, and you send them into the component as attributes.