'How to prefill CkEditor with data using React.js?

I'm creating a blog and I want to give the user the ability to update their post but I'm not sure how to pass the content data from the original post into my rich text editor.

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 >
  );
} 


Solution 1:[1]

It may help, try this ...

 <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)
              }}
            /

> 




Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1