简体   繁体   English

如何将 JSX 标签呈现为文本?

[英]How can I render JSX tags as text?

Had an idea for my portfolio, whereby I would wrap my surname in JSX component tags - JOE - with the tags as plain old paragraph text within spans, then style.有一个关于我的投资组合的想法,我将我的姓氏包裹在 JSX 组件标签中 - JOE - 将标签作为跨度内的普通旧段落文本,然后设置样式。 But the tags are obviously being interpreted by my code editor as JSX tags, rather than text, throwing errors.但是标签显然被我的代码编辑器解释为 JSX 标签,而不是文本,抛出错误。

Does anyone know of an element that would wrap around the tags, rendering them as text?有谁知道一个元素会环绕标签,将它们呈现为文本? Tried a few things but can't figure it out.尝试了一些东西,但无法弄清楚。

<h1> JOE <span className='neon'> < </span> BLOGGS <span className='neon'> /> </span> </h1>

To render HTML markup as text you can use HTML entities .要将 HTML 标记呈现为文本,您可以使用HTML 实体 Replace < with &lt;<替换为&lt; and > with &gt;>&gt; :

<h1> JOE <span className='neon'> &lt; </span> BLOGGS <span className='neon'> /&gt; </span> </h1>

您可以尝试将其包裹在花括号{} ,表示它是一个 JavaScript 表达式

  <h1> JOE <span className='neon'> {'<'} </span> BLOGGS <span className='neon'> {'/>'} </span> </h1>

您可以尝试{'/>'}将字符显示为文本

您可以使用直接{'<'} , {'>'}作为表达式或 HTML 实体&lt;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM