Estoy creando un blog y quiero darle al usuario la posibilidad de actualizar su publicación, pero no estoy seguro de cómo pasar los datos de contenido de la publicación original a mi editor de texto enriquecido.
import { CKEditor } from '@ckeditor/ckeditor5-react' import ClassicEditor from '@ckeditor/ckeditor5-build-classic' function UpdatePost() { const [content, setContent] = useState('') const { post_id } = useParams(); useEffect(() => { const fetchPost = async () => { const formData = await getPost(post_id); setContent(formData.content); }; fetchPost(); }, [post_id]); const handleSubmit = async (event) => { event.preventDefault(); const updated = await updatePost({ post_id, content: content, }) }; return ( <div> <form onSubmit={handleSubmit} > <h1 class="create-post-header-text">Update Post</h1> <CKEditor config={{ placeholder: "Content..." }} class="ck-editor" editor={ClassicEditor} onChange={(event, editor) => { const data = editor.getData() setContent(data) }} /> </label> </form> </div > ); }Puede ayudar, prueba esto...
<CKEditor config={{ placeholder: "Content..." }} class="ck-editor"`enter code here` editor={ClassicEditor} data={<div dangerouslySetInnerHTML={{ __html: content }} />} onChange={(event, editor) => { const data = editor.getData() setContent(data) }} / >