Languages
[Edit]
EN

React - how to comment source code

3 points
Created by:
Dirask Community
6240

In this article, we would like to show you how to comment source code in React.

Quick solution (inside JSX):

{/* Comment inside React JSX */}

In React JavaScript we have two cases of using comments:

  • For pure┬áJavaScript lines, we use┬ácomments such as // single-line comment or /* multi-line comment */,
  • For JSX notation lines we have to wrap them┬áin curly braces additionally.

Practical example:

// ONLINE-RUNNER:browser;

// import React from 'react';
// import ReactDOM from 'react-dom';

const App = () => {
  // const [value, setValue] = React.useState();
  /*
    Some comment here..
    Some comment here...
  */
  return (
    <div>
      {
        //Some comment here...
        //Some comment here...
      }
      <div>Users:</div>
      {/*
        <div>
          <span>Name:</span>
          <span>John</span>
        </div>
       */}
    </div>
  );
};

const root = document.querySelector('#root');
ReactDOM.render(<App />, root);

Note:
Inside JSX HTML comments are not supported.

<div>
  <!-- This doesn't work! -->
</div>

ReactJS

React - comment source code
Native Advertising
­čÜÇ
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

ÔŁĄ´ŞĆ­čĺ╗ ­čÖé

Join