[英]CKEditor is not getting reloaded on react state change
I am trying to create a react component which internally uses ckeditor.我正在尝试创建一个内部使用 ckeditor 的反应组件。 But CKEditor component is not getting reloaded/re-rendered, can somebody please help.
但是 CKEditor 组件没有被重新加载/重新渲染,有人可以帮忙。
const CkEditor = ({value, onChange, className = {}}) => {
return (
<div className={className}>
<CKEditor
initData={value} onChange={onChange}
/>
</div>
)}
initData always remains the same. initData 始终保持不变。
We were able to resolve the issue in the following way.我们能够通过以下方式解决该问题。
const CkEditor = ({
value,
className = {}}) => {
const [editor, setEditor] = useState(null);
const onBeforeLoad = (e) => {
setEditor(e.editor);
}
useEffect(() => {
if (editor) {
editor.setData(value);
}
}, [value]);
return (
<div className={className}>
<CKEditor
initData={value}
onLoaded={onBeforeLoad}
/>
</div>
);}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.