如何在 React 中渲染 HTML 字符串? [英] How to render a HTML string in React?

查看:110
本文介绍了如何在 React 中渲染 HTML 字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个像 < 这样的字符串b>hi</b >.我必须将其呈现为hi".有人可以让我知道我可以在 React 中使用的 Angular 中的 innerHTML 等等价物吗?

I have a string like < b >hi< /b >. I have to render it as "hi". Can someone let me know an equivalent thing like innerHTML in Angular that I can use in React?

推荐答案

您可以尝试使用带有封闭标签的 dangerouslySetInnerHTML:

Hi you can try dangerouslySetInnerHTML with the enclosing tag:

  <div dangerouslySetInnerHTML={{ __html: yourhtml }} />

这篇关于如何在 React 中渲染 HTML 字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆