What is React?
React is a javascript library which is used for building UI(User Interfaces). Why it is library and not a framework. Because the main focus of it is to build user interfaces. It does not focus on other aspects of the application. For example if you want to store data on application level we have the another library which is called as redux which seamlessly integrated with react.
So there are many third party library which are there which can be easily integrated with react. And these third party libraries are the ones which are taking care of the other aspects of the react.
It is created and maintained by the Facebook.
Why React?
React is a component based architecture. Because of this component based architecture we can write highly reusable code. and it is much easier to maintain.
It works on the concept called as virtual DOM. And this virtual DOM concept is a bit different from the normal DOM that we know of. So updates are much faster.
Will understand the 2nd concepts by below example.
First lets understand that what is mean by component based architecture. Now let say you want to create a card component which display some data with some sort of background color. Now the data and the color is going to be different every time when user clicks on the button. Its basically going to come lets say from API. Now do you need to create component every time for different data and different color? The answer is “NO”.
You can create one component in react that is write code for one component. and just like functions takes arguments, a component can take arguments in the form of props. Basically just like passing arguments we are saying that we are able to render Data1 and the background should be green, similarly data2 with the background color red and data3 with the background color blue.
Now lets understand about the virtual DOM. Now lets say you buy a brand new car and accidentally you break the lights of car. Now is it make sense to replace the each part of the car. No right? It does not make sense. Similarly we have different parts of the application. Lets say we have updated a part of the DOM.
Now does it mean by if you have updated a part of the DOM , is it necessary to you to re render the entire DOM. This is going to be expensive and time taking. So in case of virtual DOM that react relies on , it basically re render the part of DOM which has updated. Other parts are not touched and left as it is. This makes the process of re render very fast and thats why react is faster.
Visit More: