I'm trying to do this.
const isUserConnected = localStorage.getItem('token')
{isUserConnected.length ? null :
<div className='registerLogin'>
Register...
</div>
}
The ternary isn't acting in accordance to the localStorage content.
What is wrong?
isUserConnected
is probably undefined
.
In which case your code should look more like
const token = localStorage.getItem('token')
const isUserConnected = token && token.length
{isUserConnected &&
<div className='registerLogin'>
Register...
</div>
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.