React is a popular JavaScript library that is widely used for building user interfaces. It provides a powerful and efficient way to create interactive and dynamic web applications. With React, developers can easily break down the user interface into reusable components, making the development process more organized and maintainable. React utilizes a virtual DOM (Document Object Model) which allows for efficient updates and rendering of components. This means that when a change occurs in the application, React only updates the specific component affected by the change, rather than re-rendering the entire page. This results in faster and smoother user experiences. Additionally, React follows a unidirectional data flow, where data is passed down from parent components to child components. This ensures predictable and easily manageable state management. Overall, React’s declarative syntax and efficient rendering make it a powerful tool for building modern and responsive web applications.

What is React ?

React is a declarative, efficient, and flexible JavaScript library for building user interfaces.

It lets you compose complex Uls from small and isolated pieces of code called components.

React uses virtual DOM to make real-time changes without need to refresh the page.

What is Virtual Dom ?

In React, there are two DOM, i.e., real and virtual. Both DOMs are in sync. So any change in virtual DOM automatically updates that specific portion in real DOM.

The virtual DOM (VDOM) is a programming concept where an ideal, or “virtual”, representation of a UI is kept in memory and synced with the “real” DOM by a library such as ReactDOM. This process is called reconciliation.

This approach enables the declarative API of React: You tell React what state you want the UI to be in, and it makes sure the DOM matches that state. This abstracts out the attribute manipulation, event handling, and manual DOM updating that you would otherwise have to use to build your app.

Since “virtual DOM” is more of a pattern than a specific technology, people sometimes say it to mean different things. In React world, the term “virtual DOM” is usually associated with React elements since they are the objects representing the user interface. React, however, also uses internal objects called “fibers” to hold additional information about the component tree. They may also be considered a part of “virtual DOM” implementation in React.

Is the Shadow DOM the same as the Virtual DOM?

No, they are different. The Shadow DOM is a browser technology designed primarily for scoping variables and CSS in web components. The virtual DOM is a concept implemented by libraries in JavaScript on top of browser APIs.

What is JSX ?

JSX is combination of JavaScript and HTML.

JSX is a syntax extension for JavaScript that allows XML/HTML-like content to coexist with JavaScript code. JSX is mainly used with the React framework, but can also be used with other implementations1. Here are some examples of JSX code:

Create React Project

You can set up a React project by running the following command in your terminal:

Directory Structure

The public directory constains the index.html file where React inject all the code.

The src directory houses all the JavaScript file (components, hooks, assets, context) where we write React components.

Getting Started (code)

We create a function (component) and export it from the file. The function returns a single div that contains all other JSX elements.

Event Handler

Let’s remove everything, create a button and add an event handler by passing the function name to {} brackets.

Run React Project

You can run the project using running npm start in your project terminal.

Trending

Design a site like this with WordPress.com
Get started