EN
React - how to comment source code
3 points
In this article, we would like to show you how to comment source code in React.
Quick solution (inside JSX):
xxxxxxxxxx
1
{/* Comment inside React JSX */}
In React writing source code in JavaScript we have two cases of using comments:
- pure JavaScript lines, we use comments such as:
// single-line comment
or/* multi-line comment */
, - JSX notation lines we have to wrap them in curly braces additionally, e.g.
{/* comment */}
.
Practical example:
xxxxxxxxxx
1
// import React from 'react';
2
// import ReactDOM from 'react-dom';
3
4
const App = () => {
5
// const [value, setValue] = React.useState();
6
/*
7
Some comment here..
8
Some comment here...
9
*/
10
return (
11
<div>
12
{
13
//Some comment here...
14
//Some comment here...
15
}
16
<div>Users:</div>
17
{/*
18
<div>
19
<span>Name:</span>
20
<span>John</span>
21
</div>
22
*/}
23
</div>
24
);
25
};
26
27
const root = document.querySelector('#root');
28
ReactDOM.render(<App />, root);
Note:
Inside JSX HTML comments are not supported.xxxxxxxxxx
1<div>
2<!-- This doesn't work! -->
3</div>