I am trying to render 'Loading...' as a user awaits the Firebase sign in with Google feature to fully complete.
I am trying to conditionally render something only if the variable evaluates to true, but at this time it is rendering even though it evaluates to false (I am logging it to the console to check it)
if (!sessionStorage.getItem('isLoading')) sessionStorage.setItem('isLoading', false)
const loadingFromSessionStorage = sessionStorage.getItem('isLoading')
console.log('loadingFromSessionStorage: ', loadingFromSessionStorage) //false
useEffect(() => {
auth
.getRedirectResult()
.then(function (result) {
if (result.credential) {
sessionStorage.setItem('isLoading', false)
}
})
.catch(function (error) {
var errorMessage = error.message
})
}, [])
function handleSignInWithGoogle() {
sessionStorage.setItem('isLoading', true)
signInWithGoogle()
}
return (
loadingFromSessionStorage ? ( //this is false, but 'Loading' will *NOT* show.
<div>
//...
</div>
) : ( <h3> Loading ... </h3> )
Even when I tried to use &&
it would still render the div
//it will show the div, even though loadingFromSessionStorage is false.
return ( loadingFromSessionStorage && <div> content </div> )