New library to safely render HTML without dangerouslySetInnerHTML


(Milesj) #1

For the past few months I’ve been working on a library to safely render HTML without using dangerouslySetInnerHTML. Everyone knows how hacky that approach is and how dirty it makes you feel, so hopefully this library will rid that feeling!

I call it Interweave, because it interweaves React elements throughout a string. The library can be found here: https://github.com/milesj/interweave

It also does much more than simply render HTML. It can match patterns and replace with React elements. It can filter and clean values to avoid vulnerabilities. It supports emojis, and much more!

Let me know what you think!


(Kevin Kirchner) #2

This seems like a fun idea. Have you toyed with the idea of using this for translation tools? One area I feel react lacks in is the managing content side of things… making it easier to dynamically add html content in various places of the site seems like a step in the right direction… maybe?


(Milesj) #3

I’ve not thought about that before, but is definitely something that might be doable. The HTML parser in Interweave is quite powerful.


(Arman Nisch) #4

milesj, thank you for this library.