reactjs - Draft-js 所见即所得更新 onEditorStateChange 之外的内容状态
问题描述
有没有办法在 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}
/>
解决方案
推荐阅读
- php - Why can't I get data from SQL row using PHP prepared statements?
- javascript - match values start or end dates in javascript
- vue.js - 如何在设置数据后强制焦点 - VueJS
- vue.js - Vue emit will not be important in other component
- nodes - AEM Large number of modified child nodes
- android - How to read from a file descriptor on Android
- laravel - Vue JS and Video JS "ID supplied is not valid" error
- javascript - Code stuck on site even after cleaning caches
- docker - 以非管理员身份运行但不以管理员身份运行时可见的注册表项
- r - R Shiny error - cannot coerce type 'closure' to vector of type 'character'