Why react is not an mvvm framework

WBOY
Release: 2022-04-21 17:30:24
Original
1449 people have browsed it

Because react is one-way data binding, and the most significant feature of mvvm is two-way data binding; the mvvm framework requires a vm object to map the view, but react does not have a vm in a pure sense. Objects have properties and states, so react is not an mvvm framework.

Why react is not an mvvm framework

The operating environment of this tutorial: Windows 10 system, react17.0.1 version, Dell G3 computer.

Why react is not an mvvm framework

mvvm

First understand what mvvm means. vm means view mode.

So the mvvm framework requires a vm object to map the view.

That is, when the attributes of the vm object change, the corresponding view part will be updated accordingly. The more classic one is knockoutjs, in which the key concepts are view model, compute, view template, etc. Yes, there are actually a lot of its shadows in vue.

react

Then let’s take a look at react. It does not have a vm object in the pure sense, it only has attributes and states.

Use attributes and states to map views. So what is the difference between attributes and states and vm? Personally, I think that the vm object will be treated equally regardless of whether the value is passed in from the outside or defined internally. In many cases, there is a two-way binding mechanism. Maybe the early flex was amazing, but the later mvvm framework has the concept of two-way binding. React, on the other hand, emphasizes attribute immutability and one-way data flow. The internal state is controlled internally.

Such a design may be more complicated in terms of design, but it becomes more certain and clearer in terms of use. If you are familiar with React, managing appropriate states for appropriate components and stratifying states reasonably will greatly reduce application complexity. Then, redux has a very advanced concept called container components and pure display components. If you understand this design idea, you can concentrate complex things into a small number of components, and most of the components will become pure display components, further reducing the complexity of the application. sex.

One of the most significant features of MVVM: two-way binding.

React does not have this, it is one-way data binding.

React is a one-way data flow library with state-driven views.

State --> View --> New State --> New View
Copy after login

Recommended learning: "react video tutorial"

The above is the detailed content of Why react is not an mvvm framework. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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 [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!