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.
The operating environment of this tutorial: Windows 10 system, react17.0.1 version, Dell G3 computer.
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
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!