Introduction to React

Author: neptune | 11th-Dec-2022
#JavaScript

What is React?

1. React is an open source library developed and maintained by the developers of Facebook, Instagram and also a larger community of contributors.

2. A declarative, efficient, and flexible JavaScript library for building user interfaces.

3. Makes developing a large scale, single-page application easier.

4. Supports all the syntax of ECMAScript 2015/ES6.

5. Can perform client-side as well as server-side rendering.


What is exciting in React?

For dynamic UI, DOM was never an optimized solution. Let's take an example of displaying a list containing 10 items and one is getting updated. To reflect the update, DOM will rebuild the entire list making it work 10 times more than what is necessary. This inefficiency can be overcome using Virtual DOM.

Virtual DOM (Document Object Model) is an abstract, lightweight copy of DOM. It can be changed as and when we want and then can be saved to the real DOM. Whenever a change occurs, Virtual DOM efficiently rerenders the DOM. It is much faster than DOM.

Virtual DOM has the same properties as a real DOM object.

React postulated the idea of Virtual DOM. It is commonly used by PayPal, Apple and Facebook.


Virtual DOM vs Real DOM

Real DOM

  • Reading and writing is really slow in DOM.

  • Changing the whole DOM each time when there is an update will slow down the page.

Virtual DOM

  • Has rapid DOM rendering speed because manipulating the virtual DOM is much faster, because nothing gets drawn on screen.

  • Only the required part of DOM is updated.


Need of React?

1. React is faster and better, because of Virtual DOM.

2. React can be used on both Client side and server side. 

3. For apps having dynamic data, you can go with client side scripting.

4. Static pages can be rendered using server side scripts. 

5. Mixture of both helps in maintaining the page safe and efficient.

6. Helps to maintain the readability of apps using components.

7. Can easily update the state by referring the components.


Building Blocks of ReactJS

A typical ReactJS program contains:

  • Components

  • Elements

  • Props

  • States

  • Functions

React Features

  • Components: Easier to maintain larger apps.

  • JSX: Optional feature of React that is a JavaScript syntax extension.

  • Frontend: React only covers the view layer of the app, so you still need to choose other technologies to get a complete tooling set for development.

  • Inline template: React is using inline templating and JSX that might be awkward to some developers.


JSX

JSX is an inline markup that looks like HTML that gets transformed to JavaScript by preprocessors. It is not mandatory to use JSX with React. But React would be elegant if JSX is used.

Syntax:

It starts with a HTML like open tag, and ends with the corresponding closing tag.

Example:

const element = <h1>Hello, world!</h1>;


The syntax is intended to be used by preprocessors such as Babel to transform HTML like text into standard JavaScript objects.

Conclusion

React is an open source library developed and maintained by the developers of Facebook, Instagram and also a larger community of contributors. Virtual DOM (Document Object Model) is an abstract, lightweight copy of DOM. JSX is an inline markup that looks like HTML.




Related Blogs
Generate Fibonacci Sequence - JavaScript | Hackerank
Author: neptune | 07th-Apr-2023
#JavaScript #Hackerrank
Write a JavaScript function fibonacciSequence() to generate a FIbonacci sequence...

To Be Or Not To Be | #2704 | LeetCode Solution
Author: neptune | 03rd-Sep-2023
#JavaScript #LeetCode
Write a function that helps developers test their code. It should take in any value and return an object with the following two functions...

Apply Transform Over Each Element in Array | #2635 | LeetCode Solution
Author: neptune | 05th-Sep-2023
#JavaScript #LeetCode
Given an integer array `arr` and a mapping function `fn`, return a new array with a transformation applied to each element...

Function Composition | #2629 | LeetCode Solution
Author: neptune | 09th-Sep-2023
#JavaScript #LeetCode
Given an array of functions [f1, f2, f3, ..., fn], return a new function fn that is the function composition of the array of functions...

Counter | #2620 | LeetCode Solution
Author: neptune | 02nd-Sep-2023
#JavaScript #LeetCode
Given an integer n, return a counter function. This counter function returns n and then n + 1, n + 2, etc...

Counter 2 | #2665 | LeetCode Solution
Author: neptune | 04th-Sep-2023
#JavaScript #LeetCode
Write function 'createCounter' It accept an initial integer 'init' It should return an object with three functions- increment() , decrement(), reset()...

Chunk Array | #2677 | LeetCode Solution
Author: neptune | 19th-Sep-2023
#JavaScript #LeetCode
Given an array arr and a chunk `size`, return a `chunked` array...

Array Reduce Transformation | #2626 | LeetCode Solution
Author: neptune | 09th-Sep-2023
#JavaScript #LeetCode
Given an integer array `nums` and a reducer function `fn`, and an initial value `init`, return a reduced array...

Managing Virtual Environments in React JavaScript Projects
Author: neptune | 28th-Jun-2023
#JavaScript #React.js
Virtual environments are a valuable tool in React JavaScript projects as they allow developers to isolate dependencies, manage package versions, and maintain project consistency...

Add Two Promises | #2723 | LeetCode Solution
Author: neptune | 12th-Sep-2023
#JavaScript #LeetCode
Given two promises `promise1` and `promise2`, return a new `promise`. `promise1` and `promise2` will both resolve with a number...

Different ways to handle state in React applications
Author: neptune | 21st-Jun-2023
#JavaScript #React.js
This article explores different ways to manage states in React, including local component state, context API, and state management libraries like Redux...

Arrow Functions in JavaScript | ES6
Author: neptune | 26th-Mar-2023
#JavaScript #React.js
In this article, we will explore the syntax and usage of arrow functions in detail, along with some examples...

Filter Elements from Array | #2634 | LeetCode Solution
Author: neptune | 06th-Sep-2023
#JavaScript #LeetCode
Given an integer array `arr` and a filtering function `fn`, return a filtered array `filteredArr`...

Is Object Empty | #2727 | LeetCode | JavaScript Solution
Author: neptune | 01st-Sep-2023
#JavaScript #LeetCode
Given an object or an array, return if it is empty...

From REST to GraphQL: The Future of API Design
Author: neptune | 25th-Feb-2024
#JavaScript
Unlike traditional REST APIs, GraphQL provides a more flexible and intuitive approach to data querying and retrieval...

A Guide to Writing Clean, Readable, and Maintainable Code in JavaScript
Author: neptune | 23rd-Feb-2024
#JavaScript
By incorporating these principles into your coding practices, you contribute to creating code that is not only functional but also maintainable and easily understandable by your peers...

How I Built My Blogging Website Using React, Node.js, and Jamstack Architecture?
Author: neptune | 31st-Jul-2024
#JavaScript #API
Building a blogging website using React, Node.js, and Jamstack architecture was a rewarding experience...

How to Perform Unit Testing in React Components with Examples?
Author: neptune | 25th-Jul-2024
#JavaScript #React.js
Unit testing in React is an essential practice to ensure the reliability and robustness of your components...

Do you know ! How to manage State in Functional & Class Components in React ?
Author: neptune | 25th-Jul-2024
#JavaScript #React.js
State management in React has evolved significantly with the introduction of Hooks...

Why, What, and When: Understanding Jamstack?
Author: neptune | 05th-Jul-2024
#JavaScript #API
Jamstack represents a modern approach to web development that addresses many of the challenges faced by traditional architectures...

How to Get Started with Jamstack: A Comprehensive Guide?
Author: neptune | 05th-Jul-2024
#JavaScript #API
Getting started with Jamstack involves choosing the right tools, setting up a structured development environment...

View More