CodeReaper CodeReaper - 1 month ago 21
React JSX Question

How to comment HTML within React written in TypeScript?

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>);
}
}


I have tried the above 3 ways to comment an entire line. None seem to work. I'm using Visual Studio if it makes a difference.

Answer

Wrap it in curly braces.

{/* <div>{this.state.myVal} Not Working</div> */}

A multi-line comment would be:

{/* 
  Multi
  line
  comment
*/}