Next.js Discord

Discord Forum

How to fix this hook session?

Unanswered
Yacare Caiman posted this in #help-forum
Open in Discord
Yacare CaimanOP
hi guys.. i want to ask how to fetch api using useEffect? cause in my code i put session in that array that can make issue like if i move to another tab browser dan i back again in my tab, i check in network it called session every i go back to my tab.. if i remove the session in useEffect it make another issue which when i reload my browser the api can't fetched

3 Replies

as i said before, the session hook being a dependicy of useEffect means that whenever that function changes, your getData will too
so if you don't want it to reload like that, you would need to find out why session is doing that or remove it from deps in useEffect
@riský as i said before, the session hook being a dependicy of useEffect means that whenever that function changes, your getData will too
Yacare CaimanOP
but if i remove it in useEffect deps it make can't fetch api when im reload the page.. cause i need session for authorization..