Reputation: 189
I'm having some problems with my React code. I'm trying to add authentication but it's giving me error like
./src/components/UserInfo/index.js Line 29: Parsing error: Unexpected token, expected ","
27 | 28 |
29 | {authenticated ? ( | ^ 30 | 31 | 32 |
Here is my code
import React, { Component } from "react";
import { connect } from "react-redux";
import { Avatar, Popover } from "antd";
import { userSignOut } from "appRedux/actions/Auth";
class UserInfo extends Component {
render() {
const { authenticated } = this.props;
const userMenuOptions = (
<ul className="gx-user-popover">
<li>My Account</li>
<li>Connections</li>
<li onClick={() => this.props.userSignOut()}>Logout
</li>
</ul>
);
return (
{authenticated ? (
<Popover overlayClassName="gx-popover-horizantal" placement="bottomRight" content={userMenuOptions}
trigger="click">
<Avatar src={require("assets/images/w-logo.png")}
className="gx-avatar gx-pointer" alt="" />
</Popover>
) : (
<Popover overlayClassName="gx-popover-horizantal" placement="bottomRight" content={userMenuOptions}
trigger="click">
<Avatar src={require("assets/images/w-logo.png")}
className="gx-avatar gx-pointer" alt="" />
</Popover>
)}
)
}
}
const mapStateToProps = state => {
//console.log(state.auth.token);
return {
authenticated: state.auth.token !== null,
locale: state.settings.locale
}
}
export default connect(mapStateToProps, { userSignOut })(UserInfo);
Upvotes: 0
Views: 116
Reputation: 408
The problem lies in that line because you are returning
return (
{authenticated ? (...) : (...)});
Which means, that you're trying to return an object, and that's not what you actually want. So you should change it to this:
return authenticated ? (
<Popover overlayClassName="gx-popover-horizantal" placement="bottomRight" content={userMenuOptions}
trigger="click">
<Avatar src={require("assets/images/w-logo.png")}
className="gx-avatar gx-pointer" alt="" />
</Popover>
) : (
<Popover overlayClassName="gx-popover-horizantal" placement="bottomRight" content={userMenuOptions}
trigger="click">
<Avatar src={require("assets/images/w-logo.png")}
className="gx-avatar gx-pointer" alt="" />
</Popover>
);
Upvotes: 5