我有一个textArea,可以通过超时保存一段文字。
const TIMEOUT_MS = 1000;
getInitialState() {
return {newNote: this.props.notes};
}
componentWillReceiveProps(nextProps) {
// this is necc, because if another user saves the note, it will come via
// websockets, and we want to show this user that note
if (this.props.note !=== nextProps.note) {
this.setState({newNote: nextProps.note});
}
},
render() {
...
<input
value={this.state.newNote}
onChange={e => {
const v = e.target.value;
this.setState({newNote: v});
window.clearTimeout(this.timeout);
this.timeout = window.setTimeout(
_ => api.save(this.state.newNote),
TIMEOUT_MS
);
}} />
}
考虑这种情况
有没有一个优雅的解决方案来处理这个问题?
现在,我正在考虑在服务器上使用updated-at
密钥,并将其与客户端进行比较updated-at