Appearance
This rule prevents comment strings (e.g. beginning with // or /*) from being accidentally injected as a text node in JSX statements.
//
/*
In JSX, any text node that is not wrapped in curly braces is considered a literal string to be rendered. This can lead to unexpected behavior when the text contains a comment.
// Incorrect: const Hello = () => { return <div>// empty div</div>; }; const Hello = () => { return <div>/* empty div */</div>; }; // Correct: const Hello = () => { return <div>// empty div</div>; }; const Hello = () => { return <div>{/* empty div */}</div>; };
react/jsx-no-comment-textnodes Suspicious ​
What it does ​
This rule prevents comment strings (e.g. beginning with
//
or/*
) from being accidentally injected as a text node in JSX statements.Why is this bad? ​
In JSX, any text node that is not wrapped in curly braces is considered a literal string to be rendered. This can lead to unexpected behavior when the text contains a comment.
Example ​
References ​