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 (
<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>
)
}
}
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?
{/* JSX comment*/}
{/* comment here */}
, however for javascript// comment here
works. So, the answer depends on where you want to comment.{ // comment
with the unfortunate side-effect that you have to put the closing}
on another line. Which stinks, because the{/* JSX comment*/}
comment breaks, eg, trying to insert a block comment that completely wraps a JSX section with the/* */
construction. Why would I block comment out a JSX block? Maybe to temporarily have anotherreturn
while testing. Not saying super-common, but I was hoping for a better work-around for that case than a line with a lone}
.