stkvtflw
stkvtflw

Reputation: 13507

How to render formatted text in ReactJS webapp?

I need to save, retrieve, render and edit formatted text in my webapp.

For example, I edit text with markddown syntax on the clientSide. I can convert it to html or save as it is. But how should i render this text when webapp receiving it as a string?

var formattedTextFromDataBase = "<p>some <em>formatted</em> text</p>"

I know about "dangerouslysetinnerhtml" - this method seemed to be a bad idea. Is there another way to deal with formatted text?

Upvotes: 4

Views: 3473

Answers (1)

Mark
Mark

Reputation: 3163

No. If you want to render html provided from an external source, dangerouslySetInnerHTML was created for that purpose. As long as the source of the html is trusted (as is the case if users are only seeing their own html rendered), it should be fine.

Upvotes: 5

Related Questions