Home  >  Article  >  Web Front-end  >  What is react? What does react mainly do? (Q&A)

What is react? What does react mainly do? (Q&A)

寻∝梦
寻∝梦Original
2018-09-11 14:07:568806browse

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