0

I just want some clarity on correct comments usage when using React in Meteor.

Do I have to use the {/* React comment */} style everywhere in my code?

I have found that the normal JavaScript comments //... and /*...*/ work in the non-JSX parts of my code (like in the component methods), but I am not sure if it is safe to use.

What is recommended/best practice?

2 Answers2

2

That is the only way to put comment inside JSX tag. You are not allowed to use regular XML comment tag i.e. <!-- This doesn't work! --> and react team has no plan of adding another style of comment.

Outside JSX tag, you can use regular javascript comment.

//comment
/*
    or comment
*/

Read more.

Example:

class Comp extends React.Component {
    componentDidMount(){
        // you can use regular js comment here
        /* 
             also multiline comment
        */
    }

    render(){
        return (
            <div>
                {/* but inside JSX, you must use comment style like this */}
                <span>Content</span>
            </div>
        );
    }
}
Niyoko
  • 7,512
  • 4
  • 32
  • 59
0

I would also add to the above answer by Niyoko Yuliawan that this works not just in React but also in Blaze. Blaze doesn't accept // commenting in the Javascript files but does accept the /* */ start and end tags. As such the above answer may be more general to Meteor than isolated to React.