gpt4 book ai didi

javascript - ReactJS 中逻辑 OR 运算符期望为 bool 值的表达式

转载 作者:行者123 更新时间:2023-12-03 02:17:06 24 4
gpt4 key购买 nike

我无法理解为什么会生成此错误,因为代码看起来完全正常。

Reactjs 组件:

const mapStateToProps = (state) => ({
isAuth: ||state.auth.uid
});

|| 上有错误运算符(operator)。阅读其他答案,我能找到的只是网络 Storm ,即便如此,在我的案例中,没有任何东西可以解决这个问题。

我正在使用 ES6 语法、babel 和 eslint airbnb 规则(如果有帮助的话)。

更新:拼写错误(|| 到 !!)

最佳答案

const mapStateToProps = (state) => ({
isAuth: state.auth.uid || 0
});

我只是假设,您希望在 isAuth 中存储 state.auth.uid(如果有效)或 0/false(如果无效)。

希望能满足您的要求。

关于javascript - ReactJS 中逻辑 OR 运算符期望为 bool 值的表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49328689/

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