React - Add Comments in JSX

Tell us what’s happening:
Hello
I keep getting an error: should use valid comment syntax.

Although I’m using the right syntax for comments as below

Your code so far
{/* comment */}
const JSX = (

This is a block of JSX

Here's a subtitle

);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36

Challenge: React - Add Comments in JSX

Link to the challenge:

const JSX = (

{/*hello*/} {/* */}

This is a block of JSX

Here's a subtitle

); // syntax is right you have to just add comment and not modify anything else in the challenge

Hi!,
The comments in JSX could actually have 2 ways. If you want to use a comment outside a JSX section use //comment or /*comment*/, but if you want to use comments inside the JSX code use this instead: {/*comment*/}.

Here is an example:

import something from 'example'
//Comment here
/*Other long
* Comment here
*/
const JSX = (
    <div>
        {/* I'm a comment */}
        Hey there
    </div>
)

Hope it helps.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.