gpt4 book ai didi

reactjs - 草案.JS : the proper way to detect content change

转载 作者:行者123 更新时间:2023-12-03 13:29:10 26 4
gpt4 key购买 nike

onChange事件,但当插入符移动或按下导航(箭头等)按钮时也会触发。

我想检测内容是否已更改。基本上我只需要在第一次更改发生时检测一次。 “比较内容”的愚蠢方式在这里可能有效,但这是一种反模式,因为此任务的资源成本太高。

最佳答案

由于 Draft 使用不可变的数据结构,因此不必占用大量资源 - 比较引用就足够了:

onChange(newEditorState) {
const currentContent = this.state.editorState.getCurrentContent()
const newContent = newEditorState.getCurrentContent()

if (currentContent !== newContent) {
// Content has changed
}
}

关于reactjs - 草案.JS : the proper way to detect content change,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41847401/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com