So I'm currently building a blogpost and the entire 'post' of this JSON file contains HTML in it, things like <p></p>
or <br>
and such. What's the most efficient way to place this in my ReactApp? I have no trouble getting everything else in but have no clue how to handle the 'post' part since different articles may have <br>
and such in different areas and would like to avoid using dangerouslySetInnerHTML or at least find a safe way of using it.
Asked
Active
Viewed 2,885 times
0

kittykittybangbang
- 2,380
- 4
- 16
- 27

Matt Nguyen
- 1
- 2
- 1
-
1Can you switch from HTML to Markdown? – gcedo Aug 27 '15 at 07:27
-
1@gcedo Markdown itself doesn't add any security unless you disable embedding HTML in it. – mik01aj Feb 01 '16 at 12:24
-
True, forgot to explicitly mention it. – gcedo Feb 01 '16 at 20:41
-
Duplicate of: Looks like a duplicate of: https://stackoverflow.com/questions/29044518/safe-alternative-to-dangerouslysetinnerhtml – theUtherSide Feb 14 '19 at 13:04
-
Possible duplicate of [Safe alternative to dangerouslySetInnerHTML](https://stackoverflow.com/questions/29044518/safe-alternative-to-dangerouslysetinnerhtml) – Michael Freidgeim Sep 23 '19 at 06:57
1 Answers
3
You can use DOMPurify to sanitize your HTML before inserting it in the DOM via dangerouslySetInnerHTML
. Hope it works!

Robert
- 5,278
- 43
- 65
- 115

Albert Olivé Corbella
- 4,061
- 7
- 48
- 66