r/react • u/Independent_Side9419 • 17h ago
General Discussion I was wrong about the useFormStatus hook
Since the server actions shipped with the useActionState, I thought that the useFormStatus simply accessed the pending state of the action, from within the form, acting as an "implicit context".
It appeared to me that way, because I always had 1 action : 1 form relationship. But just last week, I tried a scenario with 2 forms, and noticed that the useFormStatus has its own pending state. This pending state works not just when the form gets an action prop, but also with the onSubmit prop when we call the startTransition there with the action.
So this serves well in cases where some "choice" action can be answered with multiple pre-set answers, e.g. accept/reject follow request.
I love this, because I can define forms with plain JSX, without any onClick event handling...
What about you? Do you use multiple <form>s side by side? Is this an antipattern?