How to comment on .tsx file?
Asked Answered
G

2

22

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

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

Gilliland answered 12/6, 2021 at 17:11 Comment(0)
O
22

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>
Ohara answered 8/10, 2022 at 22:4 Comment(0)
S
26

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.

Stauffer answered 12/6, 2021 at 17:17 Comment(0)
O
22

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>
Ohara answered 8/10, 2022 at 22:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.