0
這真的很奇怪,因爲我已經使用了setState幾個月了,這是我第一次見到這個問題。我有一些簡單的設置狀態屬性到另一個對象的代碼。在要設置的對象中,我有一個屬性叫做GroupModel。奇怪的是,一旦這個對象被設置在setState中,屬性GroupModel get就被轉換爲一個對象,並且我失去了它的成員。我在這個對象中有其他數組屬性,它們不受影響。React的setState似乎剝離了一些項目
// just before the call to setState I check newUserGridConfig and find that its child property,
// GroupModel, is indeed an array and has the expected child elment.
self.setState({ localGridConfig: newUserGridConfig },() => {
// once setState completes I check self.state.localGridConfig.GroupModel and
// find that it is now an object (i.e. [object Object]).
// I then check newUserGridConfig.GroupModel and
// it is still an array and has the expected element in it
var response = self.updateUserGridConfigurationStore(self.state.localGridConfig,
saveNetwork);