The editor is showing
Type 'Promise' is not assignable to type 'void | Destructor'.
for the checkUserLoggedIn() call in useEffect.
I can get rid of it by doing const checkUserLoggedIn:any
However maybe that's not the most ideal way of solving this...
If I do const checkUserLoggedIn:Promise I then get a different error:
This expression is not callable. Type 'Promise' has no call signatures.
which is not what I want...I want it to be callable...I'm translating/converting my javascript file to typescript.....
useEffect(() => checkUserLoggedIn(), [])
// Check if user is logged in
const checkUserLoggedIn = async () => {
console.log('checkUserLoggedIn')
const res = await fetch(`${NEXT_URL}/api/user`)
const data = await res.json()
if (res.ok) {
setUser(data.user)
console.log('data.user', data.user)
router.push('/account/dashboard')
} else {
setUser(null)
}
}
Via Active questions tagged javascript - Stack Overflow https://ift.tt/W2GBlXu
Comments
Post a Comment