React Features

<h1>What is React?

React is an important library of JavaScript, which is used to develop an interactive user interface. It is an open-source language which means the source code of this program is available for the developers to modify if needed. React was initially built and maintained by Facebook for internal use, but now it is widely adopted by startups and big companies as well. React can be used to develop small as well as big complex applications. The popularity of this library is due to the component-based architecture it follows.

<h2>Features that make it essential

React is adapted globally due to its powerful features. Some of them are mentioned below:

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/4093727/13060db3-47f4-4fdf-93b3-3b9e5d4cb711.png)

**1. Virtual DOM**
Virtual DOM is an individual Document Object Model built by React. This virtual DOM duplicates or represents the real DOM of the web application of front-end document. React creates a virtual copy of the original document so that when any changes take place in the original web application or its source code, then it updates the virtual DOM in the first place. After that the virtual DOM is compared with the real one by React to identify the changes which are necessary. This is done because only the essential changes are applied to the real DOM that helps in improving the speed and performance of the web application and also increases the responsiveness of the web page. 

**2. Component-Based Architecture**
React is mainly based on the concept of components. The component-based architecture usually helps in developing and maintaining complex user interfaces easier. [Reacts code](https://www.tpointtech.com/reactjs-tutorialhttps://www.tpointtech.com/reactjs-tutorial) is divided into smaller components in which each component consists of different style, size, and function. These components can be reused whenever or wherever it is needed. Each component is tested and built separately and then joined together to form a proper web application which is used by the users. This makes the work very easy as we can use it multiple times. 
Two main types of React components are as follows:
•	Class Components
•	Function Components

Class Components: Class components are the basic classes which are created by combination of many functions. Every component of class components is a subclass of React.Component class.

Syntax of Class Component:

```jsx
class MyName extends React.Component {
  render() {
    return <h1>Astha, {this.props.name}</h1>;
  }
}
```
Function Components: Function component is nothing but a JavaScript function. It accepts an argument and returns a React element just like [JavaScript function](https://www.tpointtech.com/javascript-function).

Syntax of Function Component:
```jsx
function function_name (argument_name) {
               function_body;
}
```
**3. JSX (JavaScript XML)**
JSX is an extension version of JavaScript syntax. JSX is mainly a method in which, instead of writing HTML and JavaScript separately, we can write HTML-like code inside the JavaScript code.

For Example,

```jsx
class Web extends React.Component {
                 render ( ){
                       return ( 
                                <p> Header </p>
                                <p> Content </p>
                                <p> Footer </p>
                        );
                 }
}    
```
JSX follows the rules and methods of JavaScript.

**4.Unidirectional Data Flow**
Data flows in a single direction only, i.e., from parent to the child component. It cannot be passed from the child component to the parent component in any case. This method simplifies and makes data handling very easy as it reduces the complexity of the given data.

**5. State**
State in React is the specified object that is used to store the dynamic data of the website in the components. It keeps the track of the component’s behaviour and changes. If any change takes place in the component, then React re-renders the component to show the same in the user interface. It can never be modified directly.

Using of State in Function Component:

```jsx
import React, {useState} from 'react';
function Countme () {
              const [count, setCount]= useState (0);
              return (
                     <div>
                            <p>Count: {count}</p>
                            <button onClick= { () => 
setCount(count+1)}>Increment</button>
                     </div>
             );
} 
```
Using of State in Class Component:

```jsx
class Countme extends React.Component {
        constructor (props) {
               super (props);
               this.state= {count: 0};
}
increment= () =>{
         this.setState ({count: this.state.count+1});
}
render () {
         return(
                <div>
                   <p> Count: {this.state.count} </p>
                   <button onClick= {this.increment}> Increment </button>
                </div>
            );
      }
}
```
**6. React Hooks**
React Hooks are used in the function components to increase or amplify the working of these components. They authorize the developers to manage state and perform the changes with them. These changes take place outside the complex functions, such as, to retrieve data or to change the DOM manually. Hooks usually works on these two rules:
**a. "Only call hooks at the top level"-** This means we cannot call hooks inside a loop or a nested statement to make sure that they are called in an order
**b. "Only call hooks from React functions"-** This mainly means that do not call hooks from the plain JavaScript function.

**7. Server-Side Rendering**
Server-side rendering or SSR, is the process in which the client-side JavaScript server is rendered on the server instead of the browser. This helps in improving the performance of web applications, especially for those who have slow internet connections or devices. But somehow it makes the web application more complex and also not needed in all cases. It is mostly used when the site has heavy organic traffic.

<h3>Conclusion

We can conclude that React has many features to make and manage web applications very easy. It also offers us features like components and virtual DOM which ensures the readability and modifications of the code without any effect on the performance or speed of the web application. This is the reason it is the most popular library to create attractive user interfaces.