【发布时间】:2019-08-23 18:38:41
【问题描述】:
我有一个文本框,其中包含一些在进行 ajax 调用后得到的文本。 当用户键入一些文本时,我将值发送到状态。 这会呈现当前文本区域,并且光标会移到行的前面。
如何避免重新渲染。我应该如何保持状态。
class Design extends React.Component{
constructor(){
super();
}
handleMessageChange(e){
let msg = e.target.innerText;
this.props.dispatch({type:'design_changed',designObj:{property:'message',value:msg}})
}
render(){
return (
<React.Fragment>
<Panel header="Message" key="2">
<div>
<div className="userscoop-content-editable-cls" contentEditable="true" onKeyUp={this.handleMessageChange.bind(this)}>{this.props.message}</div>
</div>
</Panel>
</React.Fragment>
}
function mapStateToProps(state){
let settings = state.HelloBar.template.settings;
return {
background_color: settings.background_color,
action_color:settings.action_color,
message:settings.message,
button_color:settings.button_color,
input_placeholder:settings.input_placeholder,
goal:state.HelloBar.goal
}
}
【问题讨论】: