search
HomeWeb Front-endJS TutorialWhat is react? What does react mainly do? (Q&A)

This article mainly introduces you to the basic understanding of react. Do you dare to say that you know a lot about react? If not, then take a look at this article

1. Why is Facebook building React?

Facebook engineers are working on large projects , due to their very large code base and large organization, MVC quickly became very complex. Whenever a new function or feature needed to be added, the complexity of the system increased exponentially, causing the code to become fragile. and unpredictable, as a result, their MVC is falling apart, so Facebook believes that MVC is not suitable for large-scale applications. When there are many models and corresponding views in the system, its complexity will expand rapidly, making it very difficult to understand and debug, especially It is the possible two-way data flow between the model and the view.

Based on the above reasons, Facebook believes that MVC cannot meet their expansion needs. In order to solve the above problems, they need to "organize the code in some way to make it more usable." Prediction", so they proposed Flux and React to implement it.

2、 What is React?

##React It originated as an internal project at Facebook. Because the company was not satisfied with all the JavaScript MVC frameworks on the market, it decided to write its own to build the Instagram website. After making it, I found that this set of things is very useful, so it was open sourced in May 2013.

React is a JavaScript library for building user interfaces. React is mainly used for building UI, many people think React is the V (view) in MVC. React has high performance and very simple code logic. More and more people have begun to pay attention to and use it.

3. What problem does React solve?

We built React to solve one problem: building large applications with data that changes over time. Build large-scale applications where data changes over time

4. React features

1.Declarative design −React adopts a declarative paradigm, which makes it easy to describe applications.

2.Efficient −React minimizes the interaction with DOM by simulating DOM.

3.Flexible −React works well with known libraries or frameworks.

4.JSX − JSX is Extension of JavaScript syntax. ReactDevelopment does not necessarily use JSX, but we recommend using it.

5.ComponentBuild components through React, making the code easier to reuse and can be well applied in the development of large projects.

6.One-way response data flow − React implements a one-way response data flow, thereby reducing repeated code, which is why it is simpler than traditional data binding.

5. Main principles of React

Traditional In web applications, DOM operations are generally directly updated, but we know that DOM updates are usually relatively expensive. In order to reduce operations on the DOM as much as possible, React provides a different and powerful way to update the DOM instead of direct DOM operations. It is VirtualDOM, a lightweight virtual DOM, which is an object abstracted by React, describing what the dom should look like and how it should be presented. Through this Virtual DOM updates the real DOM, and this Virtual DOM manages the update of the real DOM. (If you want to learn more, go to the PHP Chinese website React Reference Manual column to learn)

Why can the operation of Virtual DOM be faster through this extra layer? ? This is because React has a diff algorithm. Updating VirtualDOM does not guarantee that it will affect the real DOM immediately. React will wait until the event loop ends, and then use this diff algorithm to calculate the minimum step by comparing the current new dom representation with the previous one. Update the real DOM.

The most obvious benefit is React’s so-called dom diff, which can achieve delta-level dom updates. When data changes cause DOM changes, React does not refresh globally, but calculates the differences through its internal dom diff algorithm, and then updates them with the smallest granularity. This is also the reason why React is said to have good performance.

6. Components Components

is on the DOM tree The nodes are called elements, which is different here. They are called commponents on Virtual DOM. The node of Virtual DOM is a complete abstract component, which is composed of commponents. component is used in It is extremely important in React because the existence of components makes calculating DOM diff more efficient.

7. Application

There are many foreign applications, such as facebook, Yahoo, Reddit, etc. You can see a list of Sites-Using-React on github: https://github.com/facebook/react/wiki/Sites-Using-React. If you are in China, I checked it and there seems to be relatively few. Currently, I know of one from Hangzhou. Search car. Most technologies are generally slow to be applied domestically.

8. Comparative analysis

and some other js Compared with frameworks, such as Backbone, Angular, etc., how does React compare?

1. React is not an MVC framework. It is about building web components that are easy to be called repeatedly. Focus on the UI, that is, the view layer

2. Secondly, React is a one-way rendering from data to view, not two-way data binding

3. Do not directly operate the DOM object, but use the virtual DOM to apply it to the real DOM in the smallest steps through the diff algorithm.

4. It is not convenient to directly operate the DOM. Most of the time you just program the virtual DOM

9. Relationship with React Native

Because the design idea of ​​React is extremely unique, it is a revolutionary innovation and has outstanding performance. The code logic is very simple. Therefore, more and more people are beginning to pay attention to and use it, thinking that it may be the future of the Web Mainstream tools for development.

#The project itself has grown bigger and bigger, from the earliest UI engine to a complete set of front-end and back-end Web App solutions. The derived React Native project has even more ambitious goals and hopes to use it to write Web Apps. way to write Native App. If it can be realized, the entire Internet industry will be subverted, because the same group of people only need to write the UI once and it can run on the server, browser and mobile phone at the same time.

This article ends here (if you want to see more, go to the PHP Chinese websiteReact User ManualLearning in the column), if you have any questions, you can leave a message below.

The above is the detailed content of What is react? What does react mainly do? (Q&A). For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Python vs. JavaScript: Development Environments and ToolsPython vs. JavaScript: Development Environments and ToolsApr 26, 2025 am 12:09 AM

Both Python and JavaScript's choices in development environments are important. 1) Python's development environment includes PyCharm, JupyterNotebook and Anaconda, which are suitable for data science and rapid prototyping. 2) The development environment of JavaScript includes Node.js, VSCode and Webpack, which are suitable for front-end and back-end development. Choosing the right tools according to project needs can improve development efficiency and project success rate.

Is JavaScript Written in C? Examining the EvidenceIs JavaScript Written in C? Examining the EvidenceApr 25, 2025 am 12:15 AM

Yes, the engine core of JavaScript is written in C. 1) The C language provides efficient performance and underlying control, which is suitable for the development of JavaScript engine. 2) Taking the V8 engine as an example, its core is written in C, combining the efficiency and object-oriented characteristics of C. 3) The working principle of the JavaScript engine includes parsing, compiling and execution, and the C language plays a key role in these processes.

JavaScript's Role: Making the Web Interactive and DynamicJavaScript's Role: Making the Web Interactive and DynamicApr 24, 2025 am 12:12 AM

JavaScript is at the heart of modern websites because it enhances the interactivity and dynamicity of web pages. 1) It allows to change content without refreshing the page, 2) manipulate web pages through DOMAPI, 3) support complex interactive effects such as animation and drag-and-drop, 4) optimize performance and best practices to improve user experience.

C   and JavaScript: The Connection ExplainedC and JavaScript: The Connection ExplainedApr 23, 2025 am 12:07 AM

C and JavaScript achieve interoperability through WebAssembly. 1) C code is compiled into WebAssembly module and introduced into JavaScript environment to enhance computing power. 2) In game development, C handles physics engines and graphics rendering, and JavaScript is responsible for game logic and user interface.

From Websites to Apps: The Diverse Applications of JavaScriptFrom Websites to Apps: The Diverse Applications of JavaScriptApr 22, 2025 am 12:02 AM

JavaScript is widely used in websites, mobile applications, desktop applications and server-side programming. 1) In website development, JavaScript operates DOM together with HTML and CSS to achieve dynamic effects and supports frameworks such as jQuery and React. 2) Through ReactNative and Ionic, JavaScript is used to develop cross-platform mobile applications. 3) The Electron framework enables JavaScript to build desktop applications. 4) Node.js allows JavaScript to run on the server side and supports high concurrent requests.

Python vs. JavaScript: Use Cases and Applications ComparedPython vs. JavaScript: Use Cases and Applications ComparedApr 21, 2025 am 12:01 AM

Python is more suitable for data science and automation, while JavaScript is more suitable for front-end and full-stack development. 1. Python performs well in data science and machine learning, using libraries such as NumPy and Pandas for data processing and modeling. 2. Python is concise and efficient in automation and scripting. 3. JavaScript is indispensable in front-end development and is used to build dynamic web pages and single-page applications. 4. JavaScript plays a role in back-end development through Node.js and supports full-stack development.

The Role of C/C   in JavaScript Interpreters and CompilersThe Role of C/C in JavaScript Interpreters and CompilersApr 20, 2025 am 12:01 AM

C and C play a vital role in the JavaScript engine, mainly used to implement interpreters and JIT compilers. 1) C is used to parse JavaScript source code and generate an abstract syntax tree. 2) C is responsible for generating and executing bytecode. 3) C implements the JIT compiler, optimizes and compiles hot-spot code at runtime, and significantly improves the execution efficiency of JavaScript.

JavaScript in Action: Real-World Examples and ProjectsJavaScript in Action: Real-World Examples and ProjectsApr 19, 2025 am 12:13 AM

JavaScript's application in the real world includes front-end and back-end development. 1) Display front-end applications by building a TODO list application, involving DOM operations and event processing. 2) Build RESTfulAPI through Node.js and Express to demonstrate back-end applications.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.