React内部,key值不相同时,会重新创建组件
为FilterPicker 提供一个key值,React内部自然会对组件的key值进行一个判断,
当key值不同的时候 会删除改组件 重新创建改组件
renderFilterPicker = () => {
const {
openType,
filterData: { area, subway, rentType, price },
selectedValue
} = this.state;
let data = [], cols =3, defaultValue =selectedValue[openType] ;
if (openType !== "area" && openType !== "mode" && openType !== "price") {
return null;
}
switch (openType) {
case "area":
data = [area, subway];
cols = 3;
break;
case "mode":
data = rentType;
cols = 1;
break;
case "price":
data = price;
cols = 1;
break;
default:
break;
}
return (
<FilterPicker
key={openType}
type={openType}
onCancel={this.onCancel}
onSave={this.onSave}
data={data}
cols={cols}
defaultValue={defaultValue} />
);
};
|