0

I'm developing in react, but I suppose that this question is applicable to any language mixing javascript and HTML.

I would like to know if there's an easy way of commenting HTML code inside a js file

For example inside the return function I usually have something like:

return (
  <View style={styles.container}>
    <Text style={styles.text}>Text 1</Text>
    <Text style={styles.text}>Text 2</Text>
    <Text style={styles.text}>Text 3</Text>
  </View>
);

I would be very useful for me to comment Text2 I tried using the HTML comment <!-- --> but it complains about the ! being an unexpected token.

Failed building JavaScript bundle.
SyntaxError: /home/isaac/Projects/AwesomeProject2/App.js: Unexpected token (20:5

What is the best way of commenting the HTML code inside javascript files?

2 Answers2

2

Use {/* ... */} to comment JSX code.
Also most editors support the Ctrl + / shortcut to comment out code with the appropriate syntax.

More info: https://wesbos.com/react-jsx-comments

domenikk
  • 1,723
  • 1
  • 10
  • 12
  • I tried with `{# #}` and did not work. But using `{/* */}` works well. The link you provided also uses `/* */`, where did you get the `#` as a comment symbol? –  Aug 24 '20 at 12:41
0

In order to comment a line in .jsx files you need to do it like so:

return (
  <View style={styles.container}>
    {/* <Text style={styles.text}>Text 1</Text> */}
    <Text style={styles.text}>Text 2</Text>
    <Text style={styles.text}>Text 3</Text>
  </View>
);
Dom
  • 734
  • 3
  • 8