K. Hansika Herath
K. Hansika Herath

Reputation: 373

How to comment on .tsx file?

I want to comment TSX code that I showed below. How can I do that?

<Form.Group controlId="type"> <Form.Label>Type</Form.Label>

Upvotes: 27

Views: 47271

Answers (2)

Code on the Rocks
Code on the Rocks

Reputation: 17596

There are a few ways.

Single line (Option 1)

<Form.Group controlId="type">
  {/* Hello World */}
  <Form.Label>Type</Form.Label>
</Form.Group>

Single line (Option 2)

<Form.Group controlId="type">
  {
    // Hello World
  }
  <Form.Label>Type</Form.Label>
</Form.Group>

Multi-line

<Form.Group controlId="type">
  {/* 
    Hello 
    World 
  */}
  <Form.Label>Type</Form.Label>
</Form.Group>

Attribute comment

<Form.Group /* Hello World */ controlId="type">
  <Form.Label>Type</Form.Label>
</Form.Group>

Upvotes: 30

Nicholas Tower
Nicholas Tower

Reputation: 84947

To add a comment in the middle of JSX, use curly brackets to pop back into plain javascript, then add your comment:

<Form.Group controlId="type">
  {/* Hello World */}
  <Form.Label>Type</Form.Label>
</Form.Group>

Typescript doesn't change this.

Upvotes: 33

Related Questions