• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

266
Views
MUIRichTextEditor does not display default value present

I am new to ReactJs. I have treid many ways and solutions to show default value in text editor. But i did not find a suitable answer to it. Below piece of code is what i tried. But i do not get the editor prefilled with database value.

I want MUIRichTextEditor to show the default value in it.

Following is MUIRichTextEditor

<MUIRichTextEditor
      name="text"
      label="Start Tying...."
      toolbarButtonSize="small"
      defaultValue={this.state.text}
      inlineToolbar={true}
      onChange={this.onChange}
/>

Below is how my Editor looks like :

enter image description here

this.onChange

onChange = textData => {
    if (textData.getCurrentContent().getPlainText()) {
        this.setState({
            text: stateToHTML(textData.getCurrentContent()),
        })
    } else {
        this.setState({
            text: "",
        })
    }
};

Have imported the following:

import MUIRichTextEditor from "mui-rte";
import { stateToHTML } from "draft-js-export-html";

How is send my data to edit:

<EditForm 
    onSubmit={this.updateData}
    initialValues={this.state.databaseData}
/>

text gets sent to the edit form, but, the default value is not getting displayed

Data in database is:

{"_id":{"$oid":"61dbc710888107116046198e"},"text":"<p>Text<strong>feild</strong></p>""__v":0}

So, when I edit my text at the front end, I want MUIRichTextEditor to be prefilled with text. Since in database it is saved as html, at the front end as well, in text editor, I want to be displayed in proper format. I do not want to use hooks. Just in ReactJs.

Expected Result when I want to edit (Example):

enter image description here

I don't know how to do it. Help would be greatly appreciated. Thankyou.

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

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error