3

I am using React-Quill to add Rich text editor to my app.

have the next string store in my DB:

const text = '<p>Hello<strong> World</strong></p><p><strong>Next Line</strong></p>';

Now I want to "Render" the text const in a REACT component, but with the "Styuling" that HTML gives to it.

Hello World

Next Line

How can I do it? or other rich text editor to achieve that?

1
  • 1
    Possible duplicate of this. Also, check this Commented Aug 5, 2020 at 0:10

3 Answers 3

6

You can use dangerouslySetInnerHTML

Source: https://reactjs.org/docs/dom-elements.html#dangerouslysetinnerhtml

const text = '<p>Hello<strong> World</strong></p><p><strong>Next Line</strong></p>';

<div dangerouslySetInnerHTML={{__html:text}} />
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Mr. @Akash Gupta for your nice solution. It worked for me.
0

react-quill supports HTML strings out of the box, so there's nothing to do except set the value property of the component with the string you receive from the database.

<ReactQuill value={text} ... />

Comments

0

Yeah react-quill is the way for working with React. I also have had a small demo to demonstrate how it works (we might have to put some css files to make it looking good): https://codesandbox.io/s/hardcore-hill-mdxji?file=/src/App.js

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.