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

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b38e87-2c15a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b38e87-2c15a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?