Next.js Discord

Discord Forum

Using useFormStatus() with a custom invoked Action

Answered
gin posted this in #help-forum
Open in Discord
ginOP
Basically im trying to track the pending status of a action without wrapping a submit button function in a form.
Answered by joulev
you can't use useFormStatus there.

for custom invoked actions:
import { useTransition } from "react"

const [pending, startTransition] = useTransition()
startTransition(() => action())
View full answer

11 Replies

ginOP
How would that look like?
based on this i cant
@gin Basically im trying to track the pending status of a action without wrapping a submit button function in a form.
you can't use useFormStatus there.

for custom invoked actions:
import { useTransition } from "react"

const [pending, startTransition] = useTransition()
startTransition(() => action())
Answer
@joulev so in this case pending will only change when the action returns right?
what about using revalidatePath
it doesnt track that or?
@gin <@484037068239142956> so in this case pending will only change when the action returns right?
pending is equivalent to useFormStatus().pending here. it only becomes false when the whole network trip completes.
@gin what about using revalidatePath
yes it works there as well
@joulev yes it works there as well
ginOP
Thank you! works ❤️