我正在使用react-ions npm进行内联编辑,因为我已经获取了1个状态变量并对其进行了初始化,并且在componentWillReceiveProp中,我已经更新了该状态变量。
因此,当我在inlineValue组件的值属性中传递该状态变量时,它正在呈现初始值,但它应该呈现更新后的状态值。
import InlineEdit from 'react-ions/lib/components/InlineEdit';
class EstimateDetail extends RoleAwareComponent {
constructor(props, context) {
super(props, context);
autoBind(this);
this.state = {
ename: 'abc'
};
}
componentWillReceiveProps(nextProps) {
if (nextProps.estimateDetail.estimateDetails) {
var estimatestate = JSON.parse(JSON.stringify(nextProps.estimateDetail.estimateDetails));
this.setState({
ename:estimatestate.estimateName
}, () => console.log);
}
}
handleSave(event){
if (event.target.name === 'test') {
this.setState({ ename: event.target.value });
}
}
render() {return(
<InlineEdit name='test' optClass="form-control form-control-static" value={this.state.ename} changeCallback={this.handleSave}/>
);
}
}
}