Why React JS is popular?
“React JS is a Library not a Framework”
What is a Library?
A library in a programming language is defined as a collection of codes. To write a code in a simplest way and to import different features we use library
Example: JQuery is a Library
What is a Framework?
A Framework is defined as a package of code including functions and libraries. the complete project is dependent on the framework you use.
Example: Angular is a Framework
DOM (Document Object Model)
DOM can be explained as the representation of HTML code in webpage. The document is the webpage itself; the objects are the HTML tags. And finally, the model of DOM is a tree structure:
Virtual DOM
Every time you make a change in the code, DOM will be completely rewritten and updated. This is an expensive operation and consumes lots of time. In this point, React provides a solution: The Virtual DOM.
Benefits of Virtual DOM
1. React first creates an exact copy of the DOM
2. Then React figures out which part is new and only updates that specific part in the Virtual DOM
3. Finally, React copies only the new parts of the Virtual DOM to the actual DOM, rather than completely rewriting it.
These benefits makes a webpage more faster than a standard webpage. This is one of the reasons why React is so popular.