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

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

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

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

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

View More