0

Rich text stored in MySQL Database:

<p>Something something</p><p>Something something</p>

I fetch the Database content and store inside description state .

React code :

<div >{ description }</div>

The output is :

<p>Something something</p><p>Something something</p>

There shoult NOT be <p> tagse there and the sentences should be in 2 lines.


  • what you're looking for is [react's dangerouslySetInnerHTML](https://react.dev/reference/react-dom/components/common#common-props). – Layhout Apr 10 '23 at 02:24

1 Answers1

0

You can pass a raw HTML string to an element like so:

const description = { __html: '<p>Something something</p><p>Something something</p>' };
return <div dangerouslySetInnerHTML={description} />;

I hope this will be help you as well.