Sitemap
Bindurani

Bindurani

React

--

React is a JavaScript library for building user interfaces.

React is used to build single-page applications. It allows us to create reusable UI components.

React is a declarative, efficient, and flexible JavaScript library for building user interfaces. It lets you compose complex UIs from small and isolated pieces of code called “components”.

→Features of React.js:

  • Use JSX: It is faster than normal JavaScript as it performs optimizations while translating to regular JavaScript. It makes it easier for us to create templates.
  • Virtual DOM: Virtual DOM exists which is like a lightweight copy of the actual DOM. So for every object that exists in the original DOM, there is an object for that in React Virtual DOM. It is exactly the same, but it does not have the power to directly change the layout of the document. Manipulating DOM is slow, but manipulating Virtual DOM is fast as nothing gets drawn on the screen.
  • One-way Data Binding: This feature gives you better control over your application.
  • Component: A Component is one of the core building blocks of React. In other words, we can say that every application you will develop in React will be made up of pieces called components. Components make the task of building UIs much easier. You can see a UI broken down into multiple individual pieces called components and work on them independently and merge them all in a parent component which will be your final UI.
  • Performance: React.js use JSX, which is faster compared to normal JavaScript and HTML. Virtual DOM is a less time taking procedure to update webpages content.

→ Installation of REACT:

Step 1: Open command prompt and type the following codes..

npx create-react-app app-name
cd app-name
code .

You can start the development web server by executing the following
command in the terminal:

npm start or yarn start

If you want to build your React application for production, you can do so by
running the following command in the terminal:

npm run build or yarn build

React uses ES6, ES6 stands for ECMAScript 6. ECMAScript was created to standardize JavaScript,

All of the React components have a render function. The render function specifies the HTML output of a React component.

In ReactJS, we have mainly two types of components.

  1. Functional Components
  2. Class Components

→ Class Component:

  • The class attribute is a much used attribute in HTML, but since JSX is rendered as JavaScript, and the class keyword is a reserved word in JavaScript, you are not allowed to use it in JSX.
  • JSX solved this by using className instead.
  • A class component must include the extends React.Component statement. This statement creates an inheritance to React.Component, and gives your component access to React.Component's functions.
  • The component also requires a render() method, this method returns HTML.

→ Functional component:

  • A Function component also returns HTML, and behaves much the same way as a Class component, but Function components can be written using much less code
  • Function components are a way to write components that only contain a render method and don’t have their own state.
  • Class components are more complex than functional components. It requires you to extend from React. Component and create a render function which returns a React element. You can pass data from one class to other class components.

→ Rendering the component:

Get Bindurani’s stories in your inbox

Join Medium for free to get updates from this writer.

To use this component in your application, use similar syntax as normal HTML: <Car /> or <car><car/>

→ Arrow Functions:

  • Arrow functions allow us to write shorter function syntax:

Without using arrow function

Using arrow function

→ React Fragments:

  • Whenever we want to render something on the screen, we need to use a render method inside the component.
  • This render method can return single elements or multiple elements.
  • The render method will only render a single root node inside it at a time. However, if we want to return multiple elements, the render method will require a ‘div’ tag and put the entire content or elements inside it.
  • This extra node to the DOM sometimes results in the wrong formatting of your HTML output and also not loved by the many developers.

Using full syntax

Using short syntax

-> Import the required components and route them.

import {Routes, Routes} from ‘react-router-dom'; helps in routing the components.

  • > For routing to any page error or page not found we use “ * ” symbol

Task 26:

Press enter or click to view image in full size

Task 27:

Press enter or click to view image in full size
Press enter or click to view image in full size

--

--