Is React library or framework
More about React
JSX and HTML are the same?
Data flow in React
In react data flow in one direction from parent to children. If you want to send data from parent component to child component you have to use props. The advantages of one way data flow or unidirectional data flow are:
1.it’s less error prone, as you have more control over your data
2.it’s easier to debug, as you know what is coming from where
3.it’s more efficient, as the library already knows what the boundaries are of each part of the system
How does React work?
ReactJs uses Virtual DOM which makes it faster as compared to other frameworks like Angular and VueJS. React makes the DOM tree-like structure of all the components internally called the VDOM.
React also has the state and props, which holds the data of the application and is used to pass that across the components in the hierarchy.
Whenever the change in the data means state or props of the component changes then it creates another virtual DOM. Now, the comparison between the previous and the updated VDOM takes place. This checking takes place using 'Diffing Algorithm' and it's quite faster than checking with the actual DOM.
Thus, whatever the changes are detected in the comparison of the two virtual DOMs in the memory gets updated in the actual DOM directly. This process is known as 'Reconciliation.
Rendering of the DOM is a very tedious and slow process. Because it involves the CSS parsing for the layout changes and HTML parsing for UI calculations. Hence, Virtual DOM is faster in comparison because it does not involve the complete render of the page.