How can I use comments inside the render method in a React component?
I have the following component:
\'use strict\';
To summarize, JSX doesn't support comments, either html-like or js-like:
/* This will be rendered as text */
// as well as this
and the only way to add comments "in" JSX is actually to escape into JS and comment in there:
{/* This won't be rendered */}
{// just be sure that your closing bracket is out of comment
}
if you don't want to make some nonsense like
actually, there are other stupid ways to add "comments"
but cluttering your DOM is not a good idea
Finally, if you do want to create a comment node via React, you have to go much fancier, check out this answer.