ReactJS - How to use comments?

后端 未结 13 1792
情深已故
情深已故 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:36

    Here is another approach that allows you to use // to include comments:

    return (
      
    { // Your comment goes in here. }
    { // Note that comments using this style must be wrapped in curly braces! }
    );

    The catch here is you cannot include a one-line comment using this approach. For example, this does not work:

    {// your comment cannot be like this}
    

    because the closing bracket } is considered to be part of the comment and is thus ignored, which throws an error.

提交回复
热议问题