如何在用TypeScript编写的React中注释HTML?

Cod*_*per 1 visual-studio typescript reactjs

class MyClass extends React.Component<any, any> {
    render(): JSX.Element {
        return (<div>
            /*<div>{this.state.myVal} Not Working</div>*/
            ///<div>{this.state.myVal} Not Working</div>
            <!--<div>{this.state.myVal} Not Working</div>-->
            </div>);
    }
}
Run Code Online (Sandbox Code Playgroud)

我尝试了以上3种方式来注释整行。似乎没有任何工作。我正在使用Visual Studio,如果有所作为。

小智 8

/* the regular JavaScript comment */花括号括起来:

{/* <div>{this.state.myVal} Not Working</div> */}
Run Code Online (Sandbox Code Playgroud)

多行注释为:

{/* 
  Multi
  line
  comment
*/}
Run Code Online (Sandbox Code Playgroud)

  • 乌拉传奇。谢谢 (2认同)