Why can vue assign values to data directly, but react can't modify the variables of state?

for complex data types, such as arrays or objects,
can be used in Vue:

data() {
    return {
        obj: dataObject
    }
}
method: {
    modify: function(newObj) {
        this.obj = newObj
    }
}

but react should use:

this.setState({
    obj: Object.asign({}, oldObj, newObj)
})

Vue can modify the reference of an object directly, but react cannot be modified directly. Instead, it needs to use Object.asign. What is the underlying reason? Why is that?

Mar.23,2021

Component and PureComponent Component can be divided into PureComponent without assign, because by making a shallow comparison in shouldComponentUpdate, vue uses getter setter react without


without object.assign.


status management library mobx draws lessons from the processing method of vue, so mobx can solve some of your doubts.


react's diff algorithm is mainly to compare the differences before and after the state to update. If you modify it directly, you may not be able to compare the results


vue, while the data of react is passed down

.
Menu