You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can place JavaScript comments anywhere in React/JSX you want except locations where JSX might expect a React child node. In this situation you'll have to escape the comment using { } so that JSX knows to pass that on as actual JavaScript.
4
+
5
+
Make sure you understand where you'll have to tell JSX to pass along a JS comment so a child React node is not created.
6
+
7
+
```javascript
8
+
var reactNode =<div /*comment*/>{/* use {'{}'} here to comment*/}</div>;
9
+
```
10
+
11
+
In the above code if I had not wrapped the comment inside of the `<div>` with `{ }` brackets then Babel would have converted the comment to a React text node. The outcome, unintentionally, without the `{ }` would be:
12
+
13
+
```javascript
14
+
var reactNode =React.createElement(
15
+
"div",
16
+
null,
17
+
"/* use ",
18
+
"{}",
19
+
" here to comment*/"
20
+
);
21
+
```
22
+
23
+
Which would result in the following HTML that would have unintended text nodes.
24
+
25
+
```javascript
26
+
<div data-reactid=".0">
27
+
<span data-reactid=".0.0">/* use </span>
28
+
<span data-reactid=".0.1">{}</span>
29
+
<span data-reactid=".0.2"> here to comment*/</span>
0 commit comments