有没有办法在 onEditorStateChange 之外为编辑器设置内容状态?例如在 useEffect 钩子中。
const editorFieldContent = EditorState.createWithContent(
ContentState.createFromBlockArray(convertFromHTML(field.value))
);
const [editorState, setEditorState] = useState(editorFieldContent);
const onEditorChange = (e) => {
setFieldValue(field.name,
draftToHtml(convertToRaw(editorState.getCurrentContent())));
setEditorState(e);
};
useEffect(() => {
//is there any function in draft js to set content state outside onEditorChange? something like this
editorState.setContentState(field.value)
}, [field.value])
<Editor
name={field.name}
editorState={editorState}
onEditorStateChange={onEditorChange}
/>