What is React.js?

Author: neptune | 26th-Nov-2022
#JavaScript

What is React.js?

Let me explain this with a practical example.

Imagine your favourite celebrity posting a photograph on Facebook. Now you go and like the photo and then you hag there for a while just glare that photo You know what I mean 🤫 then you see that likes count increased by count 100 since you liked the picture. There was no reload/refresh of the page, just somehow magically the count changed. This magic my friend is react.js.


So to explain it better, imagine your web page. Again I will take example of Facebook since everybody uses it and common they created react.js so billions of posts, so much traffic, millions like count. How do they manage all that a blazing speed. To do that they come up a library called react.js.


Imagine a post on Facebook. Now this post which is a container consists of multiple small parts like likes, comments, share, comment box called components. Every page can be broken  down into different components. Now you must be wondering why do we do this, we already have awesome frameworks on front end? Well if you dont you are certainly going to be amused now.


HOW REACT WORKS?

You know that entire web is based on html. It all started with a simple HTML code and people went wohoo in the 90's, Next came Javascript in 1996 with ways to interact with the HTML DOM(Document Object Model). After that Jquery came to change the contents of the HTML DOM. Next after that in 2009 came Angular.js as the daddy of front end frameworks which gave a full fledged option to create a strong frontend. 

Now if you see all these work on HTML code i.e you change HTML on basis of javascript(jquery, angular etc.). Now Javascript is much more powerful than HTML, Facebook considered this fact and decided to create the HTML itself from Javascript (dynamic content, if you know AJAX you should be able to relate to it) for which they created react.js. So to sum it up react.js creates your html from you javascript.


Now you know about components and how they work. You know react.js creates html from Javascript. But, reactjs itself is not written in vanilla javascript. React.js is written in something JSX (Java script XML). But HTML is created from Javascript right? So how do we get that JS from JSX. For this we use transpiler called Babel. Babel converts your JSX to JS which you can put in your html to create content dynamically.

WHAT MAKES REACT FAST?

React has a concept of Virtual DOM. So say your html has this transpiled generated output javascript which creates your html. Now say whenever anything is changed in a particular component that component changes. Now these changes are not pushed to the DOM directly, but instead it is pushed to something called VirtualDOM. Now at this point there is a difference which occurs between Virtual DOM and Real HTML DOM and changes are pushed to the realDOM. This is what makes it fast. Now trying linking to example I shared at the beginning of the answer. It should be clear now.


BENEFITS OF USING REACT

1. Single Page Application.

2. Entire page remains same but only few components change.

3. Code is easy to scale and maintain.

4. More functionalities as HTML is created from JS

5. Isomorphic Rendering (Server side rendering)

6. Blazing speed


Conclusion

Entire web is based on html. It all started with a simple HTML code and people went wohoo in the 90's Next came Javascript in 1996 with ways to interact with the HTML DOM(Document Object Model). React has a concept of Virtual DOM. So say you html has this transpiled generated output javascript which creates your html. This is what makes react fast and popular now days. 

Enjoy your day 🤡 !!!





Related Blogs
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...

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...

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 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()...

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...

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...

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...

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...

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...

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...

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

Allow One Function Call | #2666 | LeetCode Solution
Author: neptune | 11th-Sep-2023
#JavaScript #LeetCode
Given a function `fn`, return a new function that is identical to the original function except that it ensures `fn` is called at most once...

Memoize | #2634 | LeetCode Solution
Author: neptune | 12th-Sep-2023
#JavaScript #LeetCode
A memoized function is a function that will never be called twice with the same inputs. Instead it will return a cached value...

Array Prototype Last | #2619 | LeetCode Solution
Author: neptune | 20th-Sep-2023
#JavaScript #LeetCode
Write code that enhances all arrays such that you can call the `array.last()` method on any array and it will return the last element...

All You Need to Know About Pure Functions & Impure Functions in JavaScript
Author: neptune | 02nd-Apr-2023
#JavaScript #React.js
You should try to use pure functions whenever possible and avoid using impure functions unless necessary...

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...

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...

6 Brilliant JavaScript Frameworks for Every Developer
Author: neptune | 16th-Feb-2024
#JavaScript
JavaScript's web development with frameworks like Synaptic.js for neural networks, OpenCV.js for multimedia processing, D3.js for dynamic data visualizations, Compromise.js for efficient NLP, ConvNet...

Decode Secret Language of React: Game-Changer for Web Developers
Author: neptune | 25th-Feb-2024
#JavaScript #React.js
JSX is a syntax extension for JavaScript recommended by React for describing what the UI should look like...

State in React: Component State and Controlling Behavior
Author: neptune | 21st-Feb-2024
#JavaScript #React.js
React, a popular JavaScript library for building user interfaces, introduces the concept of state and lifecycle methods to help developers manage the dynamic nature of components...

View More