I'm currently using this answer to escape my HTML before inserting it into a <div>
using dangerouslySetInnerHTML
in my app.
However, I noticed there are also libraries like DOMPurify, which purport to be the safer approach to escaping HTML. Except that it's approximately 1000x larger of a solution, so I'm wondering if it's necessary.
I notice that the first solution in my answer seems to work well enough. I tried entering <script>alert('a')</script>
into the message box and it seemed to be escaped properly. For my purposes I'm only doing a couple simple markup transformations (bolding, italics, etc.).
Is what I'm doing enough, or do I need a more powerful solution like DOMPurify? I rather not add the dependency if it's not necessary.