gpt4 book ai didi

javascript - React 解析意外的 token

转载 作者:行者123 更新时间:2023-11-28 12:52:46 26 4
gpt4 key购买 nike

我的 React 代码遇到一些问题。我正在尝试添加身份验证,但它给了我类似的错误

./src/components/UserInfo/index.js Line 29: Parsing error: Unexpected token, expected ","

27 | 28 |

29 | {authenticated ? ( | ^ 30 | 31 | 32 |

这是我的代码

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

最佳答案

问题出在该行,因为您正在返回

return (
{authenticated ? (...) : (...)});

这意味着,您正在尝试返回一个对象,但这并不是您真正想要的。所以你应该将其更改为:

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

关于javascript - React 解析意外的 token,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59482848/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com