ReactJS - How to use comments?

后端 未结 13 1759
情深已故
情深已故 2020-12-04 08:17

How can I use comments inside the render method in a React component?

I have the following component:

\'use strict\';
          


        
13条回答
  •  时光取名叫无心
    2020-12-04 08:41

    JavaScript comments in JSX get parsed as Text and show up in your app.

    You can’t just use HTML comments inside of JSX because it treats them as DOM Nodes:

    render() {
      return (
        
    ) }

    JSX comments for single line and multiline comments follows the convention

    Single line comment:

    {/* A JSX comment */}
    

    Multiline comments:

    {/* 
      Multi
      line
      comment
    */}  
    

提交回复
热议问题