Home>Article>Web Front-end> Is react an mvvm framework?
react is not an mvvm framework. The mvvm framework needs a vm object to map the view, that is, when the properties of the vm object change, the corresponding view part will be updated accordingly; while there is no vm object in react, there are attributes and states, and the whole can be used as a View. So react is not an mvvm framework.
The operating environment of this tutorial: Windows 10 system, react17.0.1 version, Dell G3 computer.
react is not an mvvm framework
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.
Then let’s take a look at react. It does not have a vm object in a pure sense, but only attributes and states.
React can be used as the second V in MVVM, which is View, but it is not an MVVM framework.
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.
React as a whole is based on functional thinking. Components are designed as pure components, and state and logic are passed in through parameters. Therefore, in react, there is a one-way data flow. It is recommended to combine immutable to achieve data immutability.
Then let’s take a look at react. It does not have a vm object in a pure sense, but only attributes and states. Use properties 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 complex 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.
Recommended learning: "react video tutorial"
The above is the detailed content of Is react an mvvm framework?. For more information, please follow other related articles on the PHP Chinese website!