'
You are currently viewing What is React JS | Why React JS is so Popular?

What is React JS | Why React JS is so Popular?

React is a JavaScript library for building fast and interactive user interfaces. It was developed on Facebook in 2011, and currently, it’s the most popular javascript library for building user interfaces; as you can see on google, trends react is dominating the space of libraries and frameworks for building user interfaces the other two players here are angular JS and Vue JS. so if you want to expand your job opportunities as a front-end developer, you should have to React on your resume at the heart of all. React applications are components. The component is essentially a piece of the user interface, so when building applications with React.

We build many independent isolated and reusable components and then compose them to build complex user interfaces. Every React application has at least one component, which we refer to as the root component. This component represents the internal application and contains other child components, so every React application is essentially a tree of components. It should sound familiar if you have worked with angular two or higher.

Here is an example let’s imagine we want to build an application like Twitter. We can split this page into components like navbar, profile, trends, and feed. Here’s a representation of these components in a tree so audit elf we have an app, and below that, we have navbar, profile, trends, and feed.

Now feed includes several tweets components. Each tweet component can consist of a light component which we can reuse on other pages or even in different applications, so as you see, each component is a piece of UI. We can build these components in isolation and then put them together to create complex UIs. In terms of implementation, the component is typically implemented as a JavaScript class that has some state and render method, the state here is the data that we want to display when the component is rendered, and the render the method, as you can tell, is responsible for describing what the UI should look like.

The output of this render method is a React element, which is a simple plain JavaScript object that maps to a Dom. The element’s not a real Dom element. It is just a primary JavaScript object that represents that Dom element in memory, so React keeps a lightweight representation of the Dom in memory which was referred to as the virtual Dom, unlike the browser or the real Dom.

This virtual DOM is cheap to create when we change the state of a component. We get a new React element. React will then compare this element and its children with the previous one. It figures out what is changed, and then it will update apart of the real Dom to keep it in sync with the virtual Dom, so that means when building applications, we react unlike vanilla JavaScript or jQuery, we no longer have to work with the Dom API in browsers, in other words, we no longer have to write code in query and manipulate the Dom or attached event handlers to Dom elements. We change the state of our components, and React will automatically update the Dom to match that state, and that’s precisely
why this library is called React? When the state changes, React essentially reacts to the state change and update the dumb

one of the questions that I often get is React or Angular well both React and Angular are similar in their component-based architecture; however, angular is a framework or a complete solution, while React is a library that only takes care of rendering the view and ensuring that the idea is in sync with the state. Let’s all react does nothing less, nothing more for this very reason, react has a very small API to learn, so when building applications with React, we need to use other libraries for things like routing or calling HTTP services and so on, but this is not necessarily a bad thing because you get to choose the libraries that you prefer as opposed to being fixed with what angular gives you which often breaks from one version to another so that all about React.

Leave a Reply