"Let" not working well in reactjs

Im creating a system were it simply needs to read a cookie
A cookie can be either named “Default” or “Login”
when the Cookie is name "Default " it works fine but when it is called “Login”
it does not work, i find it very strange.

code:

const[cookie,setCookie,removeCookie] = useCookies(['Login']);

useEffect(() =>{
(async() =>{
 let tokenacces;
    
    if(cookie.Login !== null){
    console.log("cookie in if statement", cookie.Login)
 tokenacces = cookie.Login;
}
    else if(cookie.Default !== null){
    tokenacces = cookie.Default}

console.log("read cookie", tokenacces)

// some other codes......
})()
},[render])

it reads the cookie here:

  if(cookie.Login !== null){
   console.log("cookie in if statement", cookie.Login)

but it does not show the cookie value here:

console.log("read cookie", tokenacces)

and when cookie is name “Default” it always reads it perfectly
that makes no sense to me at all.

I’m not sure what any of this has to do with let.

Anyway:

const[cookie,setCookie,removeCookie] = useCookies(['Login']);
// ...
console.log("cookie in if statement", cookie.Login)

I don’t understand why you are checking cookie.Login. With useCookies(['Login']), since you are specifying “Login”, I would not expect that to be a prop on cookie, but maybe I am understanding this hook. Can you log out just cookie?

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.