---
title: "How to safely use dangerouslySetInnerHTML in React"
url: https://daily.dev/posts/how-to-safely-use-dangerouslysetinnerhtml-in-react-deybtdu2c
source_url: https://deadsimplechat.com/blog/how-to-safely-use-dangerouslysetinnerhtml-in-react/
type: article
source: "Community Picks"
published: 2024-03-14T15:05:43.707Z
updated: 2024-05-09T08:20:02.615Z
tags: ["react", "jsx"]
reading_time: 10
upvotes: 35
comments: 1
language: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# How to safely use dangerouslySetInnerHTML in React

**[Community Picks](https://daily.dev/sources/community)** · 10 min read · 35 upvotes · 1 comments

## Summary

Learn about the usage of dangerouslySetInnerHTML in React and how to safely use it. Avoid using it unless necessary and always sanitize the HTML before setting it with dangerouslySetInnerHTML.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://deadsimplechat.com/blog/how-to-safely-use-dangerouslysetinnerhtml-in-react/>

## Community discussion

Top comments from developers on daily.dev.

**@floatrx** · 2 upvotes

> I really don't understand why we need one more extra library just to remove useless HTML. I prefer to use regex. And for Markdown, I use react-markdown. Last also supports custom handle render custom components! But thx for sharing.

## Similar posts on daily.dev

- [Don’t just attend KubeCon \+ CloudNativeCon, Merge Forward your experience\!](https://daily.dev/posts/don-t-just-attend-kubecon-cloudnativecon-merge-forward-your-experience--l0rpp73x8) · CNCF · 0 upvotes · 0 comments
- [Announcing H2 2026 KCDs](https://daily.dev/posts/announcing-h2-2026-kcds-m96goajm1) · CNCF · 1 upvotes · 0 comments
- [Two months of Open Community Groups](https://daily.dev/posts/two-months-of-open-community-groups-asf52zhbs) · CNCF · 0 upvotes · 0 comments

---

Tags: [#react](https://daily.dev/tags/react), [#jsx](https://daily.dev/tags/jsx)

[View this post on daily.dev](https://daily.dev/posts/how-to-safely-use-dangerouslysetinnerhtml-in-react-deybtdu2c)
