React JSX,如何使用单引号呈现文本?示例<p>我</ p>

Pri*_*ens 34 javascript reactjs react-jsx

在React JSX中,我如何才能将以下文本包含在单引号中?还是其他可能需要转义的标点符号?

 return (
   <div>
     <p>I've seen the movie.</p>
   </div>     
 )
Run Code Online (Sandbox Code Playgroud)

小智 51

return (
   <div>
     <p>{"I've seen the movie."}</p>
   </div>
 )
Run Code Online (Sandbox Code Playgroud)

  • 遗憾的是 ES-Lint 将其标记为“字符串必须使用单引号”。 (2认同)

Pri*_*ens 11

没关系,它按原样运作.

正是IDE将其强调为错误


abh*_*ana 6

您可以使用“ html实体”在文本中加引号。

<Text>I&quot;ve seen the movie.</Text>
Run Code Online (Sandbox Code Playgroud)

输出:我看过电影。

或者如果要单引号,请使用以下选项:

<Text> I&apos;ve seen the movie.</Text>

<Text>{'I\'ve seen the movie.'}</Text>
{/* you can use both ticks and single quotes depending on your use. */}
<Text>{`I've seen the movie.`}</Text>
Run Code Online (Sandbox Code Playgroud)

输出:我看过电影。