Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to comment an attribute in .tsx files?

Given the following JSX code:

<div className="my-class"></div>

How can I comment out the className="my-class"?

  • /*className="my-class"*/ does not work
  • {/* className="my-class" */} does not work (TS1005:'...' expected)
like image 644
Michael_Scharf Avatar asked Apr 25 '17 17:04

Michael_Scharf


People also ask

How do you add comments in JSX?

Syntax. JSX comments begin and end with curly braces {} . Followed by the opening curly brace is a forward slash and an asterisk. After that is the comment and lastly, an asterisk, a forward slash and the closing curly brace.

What is the difference between TSX and ts?

tsx extension is used when we want to embed JSX elements inside the files while . ts is used for plain Typescript files and do not support adding JSX Elements. Save this answer.

What is a .TSX file?

A TSX file is a TypeScript (. TS) file written using JSX syntax. It contains code that is most likely part of a single-page or mobile application. TSX files can be opened in any text editor, but are meant to be opened in source code editors.


1 Answers

/*className="my-class"*/ does not work

Works fine: enter image description here

You can also do:

<div 
  // className="my-class"
  >Hello</div>
like image 77
basarat Avatar answered Sep 22 '22 23:09

basarat