Recently I tried to comment a line in my ReactNative application, and the comment broke it. I was confused because I used the Mac shortcut for commenting a line cmd + /, so I assumed VS Code would format it properly for me considering I have the language set to React. Why didn’t it work?

React’s Syntaxes

React has a few different ways to go about writing comments in your code. These are not all interchangeable either. One legitimate comment in one part of your code might break in another part. Most of it depends on whether the comment comes amongst Javascript code or JSX code.

Curly Braces with Slash and Asterisks

Within JSX code (between tags <>), curly braces {} are required to add comments. There are a few different ways we can use curly braces to add comments in our JSX code. We can sandwich our comments between a curly brace, slash, and asterisk sandwich.

#programming #javascript #vscode #react

The Different Comment Syntaxes of React
1.90 GEEK