Since React is at its core just plain JavaScript, you can add comments to your
code the same way you add comments to JavaScript code using //
for single-line
comments and /* */
for a multiline comment.
When you need to insert a comment into JSX, using <!– –>
to write comments as
you did with HTML will not work.
We can instead use the same syntax we use to write comments in JavaScript by embedding
it with {}
tags.
Just keep in mind that you cannot include a one-line comment using //
like
shown below:
The closing bracket }
becomes part of the comment and is ignored, causing an
error due to an unbound closure.
If you prefer using //
ensure that the line doesn't contain the closing
bracket like this: