How to convert received JSON data to HTML tags in React?
my code:
{JSON.stringify(setData.Element_008.value?.Element_001)}
# in Element_008
{
"type": "ItemPartBox",
"value": {
"Element_000": "<FONT COLOR='#A9D0F5'>세트 효과 레벨</FONT>",
"Element_001": "사멸 <FONT COLOR='#FFD200'>Lv.3</FONT>"
}
}
I want to apply the font tag in text
I tried JSON data to stringify data. but I want font tag…
2
Answers
Use the dangerouslySetInnerHTML prop to insert the HTML from your JSON data into a React element.
You can use the
dangerouslySetInnerHTML
prop to inject HTML text into an element, but be sure to sanitize your input before assigning the__html
value.For demonstration purposes, I chose the HtmlSanitizer library. It works out-of-the-box in the browser.