Next.js Discord

Discord Forum

Transition with server action redirect

Answered
Sun bear posted this in #help-forum
Open in Discord
Avatar
Sun bearOP
When calling a server action which calls "redirect", is there a way to show a transition state while the new page it's redirecting to is being rendered? Currently the experience on my app is just that it appears to sit there doing nothing until the new page pops in.

I'm aware that in Next 15 there's useActionState , what I'm not sure about is
1) does that hook also take into account rendering caused by redirects? IIRC next responds with all the data needed for the new page in the original server action network response so I assume it does
2) is there a way to do this in Next 14 where I dont have that hook? cant upgrade yet
Answered by joulev
const [pending, startTransition] = useTransition()
startTransition(() => serverAction())

Use the pending state to render a loading screen
View full answer

6 Replies

Avatar
const [pending, startTransition] = useTransition()
startTransition(() => serverAction())

Use the pending state to render a loading screen
Answer
Avatar
Sun bearOP
I thought startTransition could only be used for synchronous state updating stuff
Avatar
well, now you know transitions can be used with actions too
Avatar
Sun bearOP
is there any documentation for that anywhere? or just one of those things you gotta figure out yourself
Avatar
Sun bearOP
ah there we go thanks