HiveBrain v1.2.0
Get Started
← Back to all entries
snippetreactCritical

How to use comments in React

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
reacthowusecomments

Problem

How can I use comments inside the render method in a React component?

I have the following component:

'use strict';
 var React = require('react'),
   Button = require('./button'),
   UnorderedList = require('./unordered-list');

class Dropdown extends React.Component{
  constructor(props) {
    super(props);
  }
  handleClick() {
    alert('I am click here');
  }

  render() {
    return (
      
        // whenClicked is a property not an event, per se.
        
        
      
    )
  }
}

module.exports = Dropdown;


My comments are showing up in the UI.

What would be the right approach to apply single and multiple line comments inside a render method of a component?

Solution

Within the render method comments are allowed, but in order to use them within JSX, you have to wrap them in braces and use multi-line style comments.


    {/* whenClicked is a property not an event, per se. */}
    
    


You can read more about how comments work in JSX here.

Code Snippets

<div className="dropdown">
    {/* whenClicked is a property not an event, per se. */}
    <Button whenClicked={this.handleClick} className="btn-default" title={this.props.title} subTitleClassName="caret"></Button>
    <UnorderedList />
</div>

Context

Stack Overflow Q#30766441, score: 517

Revisions (0)

No revisions yet.