什么是将html字符串转换为组件的最佳方法?

时间:2019-12-19 20:12:32

标签: javascript html reactjs

我从CMS获得HTML字符串形式的“正文”内容

正文:"<h1>This is the title</h1><p>This is the body</p>"

我不想使用dangerouslySetInnerHTML={{ __html: body }}

我宁愿将内容作为对象,即:

const content = {
  h1: This is the title,
  p: this is the body,
  h1: this is another title,
  p: this is another body
}

然后,我可以将其Object.entries(content).map...放入Text组件中。

我要朝正确的方向前进吗?有什么选择?

0 个答案:

没有答案