#reactjs #react-draft-wysiwyg
Вопрос:
Есть ли какой-либо способ установить состояние содержимого для редактора за пределами 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}
/>