Transition with server action redirect
Answered
Sun bear posted this in #help-forum
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
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
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
startTransition(() => serverAction())
Use the pending state to render a loading screen
6 Replies
const [pending, startTransition] = useTransition()
startTransition(() => serverAction())
Use the pending state to render a loading screen
startTransition(() => serverAction())
Use the pending state to render a loading screen
Answer
Sun bearOP
I thought startTransition could only be used for synchronous state updating stuff
well, now you know transitions can be used with actions too
Sun bearOP
is there any documentation for that anywhere? or just one of those things you gotta figure out yourself
Sun bearOP
ah there we go thanks