Hi everyone,
So I have been trying to add an if/else statement within a const and for some reason it’s not working.
This is the current code I have that works:
export const CommentsListBeijing = ({ comments }) => (
comments.length > 0 ? <ButtonToolbar className="comment-list">
{comments.map((com) => (
<CommentsModal key={ com._id } comment={ com } city={com.city} person={com.person} location={com.location} title={com.title} content={com.content} fileLink={com.fileLink} timestamp={com.timestamp} createdBy={com.createdBy}/>
))}
</ButtonToolbar> :
<Alert bsStyle="warning">No sparks yet. Please add some!</Alert>
);
CommentsListBeijing.propTypes = {
comments: React.PropTypes.array,
};
But if I then want to add an if/else to it so I can produce a different Modal if com.adminSpark == true, I get an error.
This is my new code:
export const CommentsListBeijing = ({ comments }) => (
if (comments.length > 0 ) {
<ButtonToolbar className="comment-list">
{comments.map((com) => (
return com.adminSpark ?
/* something admin-related */ :
<CommentsModal
key={ com._id }
comment={ com }
city={com.city}
person={com.person}
location={com.location}
title={com.title}
content={com.content}
fileLink={com.fileLink}
timestamp={com.timestamp}
createdBy={com.createdBy} />
))}
</ButtonToolbar> :
<Alert bsStyle="warning">No sparks yet. Please add some!</Alert>
);
After adding this code I get an "imports/ui/components/beijing/comments-list-beijing.js:16:2: Unexpected token (16:2)“
error. Line 16 refers to the place where my first if statement starts: " if (comments.length > 0 ) {”
Can someone explain to me why?