我正在使用suneditor-react的富文本编辑器。它的所有功能都工作正常,但现在的问题是按下提交按钮后,文本区域应该是空的。
当我运行console.log时,内容显示为空,但它仍然显示在文本区域中。
视图:
<TextField id="title" label="Content title" name="title" value={contenttitle} onChange={(e) => setContenttitle(e.target.value)} autoComplete="title" margin="normal" required fullWidth autoFocus />
<div>
<SunEditor setOptions={editorOptions} width="100%" height="500px" setContent="" onChange={setContent} />
</div>
<Button onClick={handleSave} variant="contained" sx={{ mt: 3, mb: 2 }}>
Save
</Button>
脚本:
const [contenttitle, setContenttitle] = useState("");
const [content, setContent] = useState("");
const handleSave = () => {
console.log("save editor content: ", content);
. . . .
dispatch(updatemasteractivitiesThunk({ _id, body }))
.then(() => showModal("info", "confirm", "Do you want to create another content?"))
.then(() => {
setContent(""); //<------- its working but not reflect on text area
setContenttitle("");//<---- its working
});
};
**屏幕截图:**x1c 0d1x
控制台:
有没有人能帮我解决这个问题。
1条答案
按热度按时间pzfprimi1#