Next.js Discord

Discord Forum

useEffect return does not triggers after route change

Answered
Asian black bear posted this in #help-forum
Open in Discord
Avatar
Asian black bearOP
The cleanup function in useEffect does not triggers on route change. How can I work around it?
Answered by B33fb0n3
you can add the pathname as dependency to your use effect. So the useEffect will trigger on route change as well. To get the pathname use usePathname
View full answer

3 Replies

Avatar
you can add the pathname as dependency to your use effect. So the useEffect will trigger on route change as well. To get the pathname use usePathname
Answer
Avatar
Avatar
Thanks! Had this issue as well