我有一個陣營組成部分,AttributeSingleChoice
這我打電話是這樣的:陣營 - 改變狀態時的道具改變
基於新props
我接受它,我想改變其狀態,像這樣:
componentWillReceiveProps: function() {
var attributeTypes = this.selectAttributes();
this.setState({
singleChoiceAttributes: attributeTypes});
},
selectAttributes: function() {
return this.props.classification.attributes.map(function (elem) {
if(elem.attributeType == "A") {
return {description: elem.description, name: elem.name}
}
}).filter(Boolean);
},
但是,如果我用componentWillReceiveProps
,state.props
會記得老props
,而不是新的,我想。
我嘗試使用componentWillUpdate
代替,但我不能設置裏面componentWillUpdate
的狀態。
如何更改基於新道具的組件的狀態?