0

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);

1 Answer 1

5

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>
          );
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.