Reputation: 11
I am trying to create a react component which internally uses ckeditor. But CKEditor component is not getting reloaded/re-rendered, can somebody please help.
const CkEditor = ({value, onChange, className = {}}) => {
return (
<div className={className}>
<CKEditor
initData={value} onChange={onChange}
/>
</div>
)}
initData always remains the same.
Upvotes: 0
Views: 1107
Reputation: 11
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>
);}
Upvotes: 1