鍍金池/ 問(wèn)答/HTML5  HTML/ 新手提問(wèn),關(guān)于react中state里面的設(shè)定能否以不為手動(dòng)方式的添加?

新手提問(wèn),關(guān)于react中state里面的設(shè)定能否以不為手動(dòng)方式的添加?

 我現(xiàn)在有個(gè):this.state={key1:value1,key2:value2}, 
 
 那么我想要:this.state={key1:value1,key2:value2,key3:value3},
 
 但我不想手動(dòng)在state里面寫個(gè)key3:value3,
 
 我假設(shè)this.state有個(gè)push(),this.state.push(key3,value3)就可以得到我想要的
 this.state={key1:value1,key2:value2,key3:value3},
 
 那么我想問(wèn),this.state里面有沒有這么一個(gè)和我假設(shè)出來(lái)的push()功能相似的方法可以做到以
 不手動(dòng)添加的方式向this.state里面添加值?
回答
編輯回答
貓館
this.state = {key1: value1, key2: value2}

this.setState({key3: value3});

//this.state = {key1: value1, key2: value2, key3: value3};

this.setState({key1: updateValue1});

//this.state = {key1: updateValue1, key2: value2, key3: value3};
2017年7月23日 13:46