gpt4 book ai didi

reactjs - Typescript:变量被分配了一个值但从未使用过,除非它被使用

转载 作者:行者123 更新时间:2023-12-02 01:48:19 26 4
gpt4 key购买 nike

我收到 Typescript 警告:'isAuthenticated' 已分配一个值,但从未用于下面的组件 enter image description here

但是,我在组件中使用 isAuthenticated ,如下所示。

import { useAuth0 } from '@auth0/auth0-react'

const Profile: React.FC = () => {
const { user, isAuthenticated, isLoading } = useAuth0()

if (isLoading) {
return <div>Loading ...</div>
}

return (
<>
isAuthenticated && (
<div>
<img src={user?.picture} alt={user?.name} />
<h2>{user?.name}</h2>
<p>{user?.email}</p>
</div>
)
</>
)
}

export default Profile

为什么当我使用该变量时会收到此警告?

最佳答案

您使用了逻辑&&运算符错误。将 () 替换为 {}

更多信息:https://reactjs.org/docs/conditional-rendering.html

关于reactjs - Typescript:变量被分配了一个值但从未使用过,除非它被使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70638806/

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