hanko state variable is undefined even after initializing it with the Hanko instance with the Setter function #1111
Unanswered
sojinsamuel
asked this question in
Q&A
Replies: 2 comments
-
I have also tried to reproduce it, using the nextjs app router starter template for hanko. Same issue. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Resolved: useEffect(() => {
if (hanko) {
logger("From Useffect");
return;
}
setHanko(new Hanko(hankoApi ?? ""));
}, [hanko]); I am trying to escape the infine loop. But still have to debug further to see if it fits right in, if the community have any suggestions please let me know. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I was trying to log the currently logged in user id and email. When the component mounts and renders for the first time, useEffect runs and initializes the hanko state variable with the instance value. So when the function
logger()
runs after the setter function is initialized.I should see this in the console.
But its giving me undefined. okay may be due to some other hidden conflicts which i need to debug further. but there is a gist, as you can see in the code i commented out these lines in the logout function:
in purpose to see what its gonna log, is that still undefined. NO. it logs both the values. When i hit the logout Button, it does work. But when i calls the logger inside or outside of useEffect it doesnt work in any rerender.
I tried to explain what i am doing in the best way possible. I hope hanko community can help me out here to see why the hanko state variable is not undefined when the logout function runs and is undefined even after the setter function is been initialized first before calling
logger()
Beta Was this translation helpful? Give feedback.
All reactions