我收到 Typescript 警告:'isAuthenticated' is assigned a value but never used對于下面的組件

但是,我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
為什么我在使用變數時會收到此警告?
uj5u.com熱心網友回復:
你用Logical && Operator錯了。替換()為{}
更多資訊:https : //reactjs.org/docs/conditional-rendering.html
uj5u.com熱心網友回復:
這個答案只是user2740650在上面的“評論”中共享的內容的一種實作。
信用到期的信用。
import { useAuth0 } from '@auth0/auth0-react'
const Profile: React.FC = () => {
const { user, isAuthenticated, isLoading } = useAuth0()
if (isLoading) {
return <div>Loading ...</div>
}
return (
<React.fragment>
{isAuthenticated && (
<div>
<img src={user?.picture} alt={user?.name} />
<h2>{user?.name}</h2>
<p>{user?.email}</p>
</div>
)}
</React.fragment>
)
}
export default Profile
我希望以上答案可能對未來的一些jsN00b有所幫助。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/407292.html
標籤:
上一篇:Nextjs和next-redux-wrapper的Redux工具包typescript型別問題
下一篇:如何根據物件屬性值應用介面
