Can react setState specify to update the state in a separate place

for example, if there are multiple places or multiple dom attributes in the page that set the same value in state, but now, due to functional considerations, I do not want to update this value of state in all places in a certain setState, but only want to update this value in specified places, can this way be realized and help give the code?

Feb.27,2021

setState is to update only the state that you specify, and has nothing to do with anything else. For example,
this.setState ({item: {}}) just updates the value of item and does not change with other attributes.


do this?
'data2 | | data' (or what does undefined judge)
data2 does not give a value at first? When setting data2, needs to be unified, leave it empty, or go further

when you need to set it separately.
= getData2() || data`
getData2 () {
    if (data2.flag = false) {
        return undefined
    } else {
        return data2.value
    }
}
// flag

the same state attribute, multiple places share the same attribute, setState only changes one place, and react can't tell where you want to change it. Different states are represented by different values


it's best to use different state to distinguish, otherwise you have to make a lot of judgments, the logic is more complex, and the cost is higher


it doesn't work with different state software, if you don't, you have to add a lot of judgments everywhere, so why don't you write a middle Filter? Similar to the structure thought of flux?


problem is very contradictory. Why not use multiple state?

Menu