Home >Web Front-end >Front-end Q&A >What is the difference between vue and react state management?

What is the difference between vue and react state management?

青灯夜游
青灯夜游Original
2020-12-04 17:28:228018browse

Difference: The state object is immutable in react applications, and the setState method needs to be used to update the state; in vue, the state object is not necessary, and the data is managed in the vue object by the data attribute.

What is the difference between vue and react state management?

Related recommendations: "Programming Video Course"

The difference between state management in vue and react

A relatively big content in React is functional programming. If you have used the popular Redux state management library, most of your development time has been spent writing functional content.

This is just something that has become very influential in the huge JavaScript community in recent years. React didn't invent functional programming, it's a pretty old concept. But it has made itself popular among modern programming languages. It's a useful way to help me write better code.

Another characteristic of functional programming is immutability. This is a reference to what was talked about recently "Why immutability is important", but the idea is to control so-called "side effects" and make managing application state easier and more predictable.

Now, React itself is not understood to be a functional library. Mobx is a popular React state management library with mutable state. Via Vue's documentation:

MobX is very popular in the React community, and it actually uses almost the same reactive system as Vue. To a certain extent, the React MobX workflow can be considered a more detailed version of Vue, so if you use this combination and enjoy it, jumping into Vue may be a wise choice.

Mobx plus React is basically an enlarged version of Vue? — Evan You

Another popular state management option for Vue is Vuex. Quoting from an article comparing Redux and Vuex, the following comparison can be a friendly inspiration:

Similar to Redux, Vuex is also inspired by Flux. However, unlike Redux, Vuex mutates the state rather than making it immutable and replacing it entirely like Redux's "reducer" function.
This allows Vue.js to automatically know which instructions need to be re-rendered when the state changes. Instead of using dedicated reducers to decompose state logic, Vuex can organize its state logic using storage called modules.

This is a fair technical argument, coming from the main point of view of many developers. If developing in functional programming is important to you, React will probably appeal more to you (with the possible exception of using Mobx). If not, Vue might be more attractive.

The difference between Vuex and Redux

On the surface, there are some differences in store injection and usage. In Vuex, $store is directly injected into the component instance, so it can be used more flexibly: use dispatch and commit to submit updates, and read data through mapState or directly through this.$store. In Redux, each of our components needs to explicitly use connect to connect the required props and dispatch. In addition, Vuex is more flexible. The component can dispatch actions and commit updates, while Redux can only dispatch and cannot directly call the reducer for modification.

In terms of implementation principles, the biggest difference is two points: Redux uses immutable data, while Vuex’s data is variable. Therefore, Redux replaces the old state with new state every time. Vuex is modified directly. When Redux detects data changes, it compares differences through diff, while Vuex actually uses the same principle as Vue, and compares through getters/setters. The difference between these two points is also due to the different design concepts of React and Vue. . React prefers to build stable and large-scale applications, which is very professional. In contrast, Vue prefers to solve problems simply and quickly, is more flexible, and does not strictly follow rules and regulations. Therefore, it will also give people the feeling of using React for large projects and Vue for small projects.

A quick overview of the difference between vue and react

What is the difference between vue and react state management?

For more related articles, please visit PHP Chinese website ! !

The above is the detailed content of What is the difference between vue and react state management?. 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