Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

{ React jsx babel es6 webpack } How Can I Comment in render ( return ( // || /**/ ) )?

I started a project last week. Before getting back with my team, I would like to comment my code.

/* Just for the Syntax outlook */

class Foo extends React.Components {
  constructor(props) {
    super(props);  
  }
  
  render() {
    return (
    
      <div className='bar'>
        
        /*
          <p> cannot commit!!!! </p>
          
          ** Following will throw error when bundled with webpack 
        */
        
        // This throws error as well. 
      
      <div>
    )
  }
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script>

The code may seem like commenting is working, but current JSbin's setting is not set on ES6. When you run bundle it via webpack with jsx it throws an error.

Here are the following stacks

  • Node v6.0.0
  • React ES6 JSX Babel
  • Bundler Webpack

Btw, because Node v6 is out, do we still need to use babel?

like image 225
DevBear15 Avatar asked May 01 '16 06:05

DevBear15


People also ask

How do I comment code in React JSX?

In JSX, whether you want to use a single line comment or multi-line comment, the syntax will remain the same. Note: Only /* */ is used inside the curly braces. Any other character like the popular double forward slash // , will throw an error.

How do I comment in return React?

We can write comments in React using the double forward-slash // or the asterisk format /* */, similar to regular JavaScript.

What is JSX Babel?

Babel : Babel is a JavaScript compiler that transform the latest JavaScript features, which are not understandable to every browser, into a backward compatible version of JavaScript in current and older browsers or environments. JSX : JSX is a syntactical extension to JavaScript.


1 Answers

You can comment in jsx but you need to wrap it in curly braces -

{/* A JSX comment */}

{/* 
  Multi
  line
  comment
*/} 

See the React docs

like image 189
dmoo Avatar answered Sep 23 '22 11:09

dmoo