Next.js Discord

Discord Forum

Is the `isPending` flag from `useTransition` supposed to update when changing routes with next/link?

Unanswered
Little yellow ant posted this in #help-forum
Open in Discord
Little yellow antOP
Essentially what the subject says. I'm working on moving from pages router to app router and am trying to find a way to do the same thing that routeChangeStart and routeChangeComplete gave us. Mainly for analytics but a few other things like memory cleanup / etc. From what I understood from the docs I should use the useTransition hook but the isPending flag is always false. Is there something I'm missing or is that not the expected functionality?

2 Replies

Little yellow antOP
I've read that the preferred solution is to create a custom wrapper for the next/link component but that seems like a band aid when we used to have the router events. Maybe that is the way it has to be but I'm hoping there is something more global
isPending of useTransition is only true when a transition is run using the startTransition returned by this same useTransition. So no, it doesn’t work.

You are probably looking for https://www.npmjs.com/package/next-nprogress-bar.