Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

207
Views
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 >
  );
} 
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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

> 




about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!