This article introduces you to the use of React: the five major characteristics of the react framework have certain reference value. Friends in need can refer to it.
01. The era background of React
Everything in the world has its cause and effect, and the emergence of a framework must be inseparable from a specific era background. For React, there are two main backgrounds that have to be mentioned:
A large amount of business logic has been changed from back-end implementation to front-end implementation: AJAX technology The emergence of the Internet has prompted people to pursue a smoother Web interactive experience, causing a large number of complex business logic to be implemented from back-end development to front-end development. This has caused a geometric increase in the amount of front-end code. Quantitative changes lead to qualitative changes. How to organize and manage this magnitude? front-end code? How to better improve application performance? Drawing on decades of experience in back-end development, the answer, not surprisingly, is to use a large front-end framework.
- For SPA applications with complex logic, the performance of the original front-end framework is poor
: Before the advent of React, there were already backbone.js and
Angular.js
and other mature large-scale front-end frameworks. However, Facebook engineers found that when faced with complex business scenarios (for example: frequent DOM operations), these frameworks cannot bring good page performance. , so they planned to develop a framework to solve this problem. The framework they developed was React, and the solution to this problem was: useVirtual DOM
. 02. Virtual DOM
The idea of virtual DOM is actually not difficult to understand: we know that frequent DOM operations will cause the browser to perform a large number of calculations on the DOM tree. This It is the most important performance bottleneck of the front end. Therefore, as long as we can merge multiple DOM operations, and then "perform all the efforts in one operation", and perform
oneoperation on the DOM tree in a timely manner, we can greatly improve front-end performance. For React, the solution to realize this idea is to use
Virtual DOM. What we call a DOM tree is actually a JavaScript object nested in a tree structure. In the browser, changes to the DOM tree will cause the browser to perform a series of calculations. Therefore, based on the existing DOM tree structure, we can clone an identical DOM tree, that is, a "virtual DOM", and all changes will be included in the browser. It is implemented on this virtual DOM and then merged into the DOM tree in the browser to solve the performance bottleneck mentioned before. Although it is not difficult to understand, this process actually involves many complex situations and some algorithmic difficulties, which is enough to open a new article to explain. I will stop here and stop here. Table.
03. What is componentization?
Componentization is a code design pattern that means you can build some simple functions into a more complex function for use.
Componentization has two notable features:
- Encapsulation: the data required by a component is encapsulated inside the component;
- Composition: A component can be combined with other components to implement more complex business logic;
- The best thing about React is that all UI elements in React are components , and the component is just a JavaScript function. But compared to the traditional function that receives some parameters and returns a value, the React function will receive some parameters and return UI elements in the interface.
Just as a good function should comply with the "DOT" (Do One Thing) principle, a good React component cannot mix the business logic of other components. We should try to keep React components simple so that complex ones can The internal logic of React components becomes clear.
The following formula can well express the componentization idea of "view is the rendering of data" in React:
UI = render(data)
In this way, in React, the way to form a complex view It becomes very simple:
Combining components;04. Declarative code
Declarative code refers to: allowing developers to follow "what I want to do", Rather than "what do I want the computer to do", think about how to achieve business needs.
Let us briefly compare the difference between "declarative code" and "imperative code":
- Imperative code:
- Feeling that the weather is too hot, Writing code:
1. 拿起空调遥控器; 2. 打开空调; 3. 设置温度为 27 摄氏度;
Declarative code: - Feeling that the weather is too hot, writing code:
1. 调用“开空调(27)”函数;
Looks like, declarative The code is just
, but in essence, this is a better programming thinking, which allows us to no longer just focus on how to implement functions through code , but more thinkingIn order to realize business logic, what functions (functions) are needed by the code, thinking about the design of functions and the relationship between functions make our code logic clearer , rich in order. In React, the data is organized in a tree shape, flowing in one direction from top to bottom (corresponding to the DOM tree). The reason for this design is: The clearer the data flow, the more controllable the status of the component; For single-page applications with complex business logic, the front-end accepts a large amount of data, and the relationship between the data is also It is complicated, and React adopts component development. Different UIs change according to different data. Without a clear and reasonable data flow management method, the final code can only be a mess. Once there is an error in the UI or data, it will be difficult to troubleshoot the error. Where is the source? In view of this, React uses a "one-way data flow" approach that only allows data to flow from parent elements to child elements. The mechanism of React's one-way data flow is roughly as follows: data is stored on the parent component and flows downward to the child component. Although the data is stored on the parent component, both parent and child components can use this data. However, if the data needs to be updated, then only the parent component should be updated. If the child component needs to modify the data, it can only send updated data to the parent component, where the data is actually updated. Once the data is updated by the parent component, the child component will receive the new data. One-way data flow sounds like it adds extra work, but it makes it easier for developers to figure out how the application works. We can easily ignore this feature of React, that is, in React, there is no special proprietary React syntax that needs to be understood and remembered, all Components, data operations, and business logic are all implemented using JavaScript syntax. This means that if you want to use React, you only need to understand the ideas of React and a few key APIs, and you can immediately start using React to develop complex applications. And React also encourages you to use functional programming ideas for development. You can use any of your functional programming skills in React development. In this article we first talked about the background of the React framework, and then explained the five major characteristics of React: Virtual DOM; Componentization; Declarative code; One-way data flow; Pure JavaScript syntax; Related recommendations: 05. One-way data flow
06. Pure JavaScript syntax
07. Summary
The above is the detailed content of Use of React: Five major features of the react framework. For more information, please follow other related articles on the PHP Chinese website!

JavaScript runs in browsers and Node.js environments and relies on the JavaScript engine to parse and execute code. 1) Generate abstract syntax tree (AST) in the parsing stage; 2) convert AST into bytecode or machine code in the compilation stage; 3) execute the compiled code in the execution stage.

The future trends of Python and JavaScript include: 1. Python will consolidate its position in the fields of scientific computing and AI, 2. JavaScript will promote the development of web technology, 3. Cross-platform development will become a hot topic, and 4. Performance optimization will be the focus. Both will continue to expand application scenarios in their respective fields and make more breakthroughs in performance.

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.

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 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 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.

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 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.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Notepad++7.3.1
Easy-to-use and free code editor
