Lea*_*ner 4 html comments jsx reactjs
我正在使用 ReactJS,我需要在 JSX 中添加可见的 HTML 注释(在 html 源代码中),但我不知道该怎么做。
第三方供应商需要此注释来对注释之间的 html 进行一些处理。
<!-- trans_disable_start -->
<div> testing </div>
<!-- trans_disable_end-->
Run Code Online (Sandbox Code Playgroud)
我尝试了以下选项,但在 html 源中看不到评论。
{/* <!-- trans_disable_start -->*/}
Run Code Online (Sandbox Code Playgroud)
尝试使用这个库 - react-render-html
{renderHTML('<!-- trans_disable_start -->')}
Run Code Online (Sandbox Code Playgroud)
任何想法/想法表示赞赏。
更新 1:
我尝试使用下面的 JS 库,但这不起作用,因为我使用的是服务器端渲染,并且我在初始加载时在页面源中看到以下值(而不是评论)
https://github.com/optimalisatie/react-jsx-html-comments
<react-comment data-reactid="18">trans_disable_start</react-comment>
Run Code Online (Sandbox Code Playgroud)
我认为dangerouslySetInnerHTML可以为你工作。
例子
<div dangerouslySetInnerHTML={{__html: "<!-- some comment -->"}} />
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2003 次 |
| 最近记录: |