Form action loading state (to prevent duplicate submissions) #9328
-
Hi, I have a form with an action, and I want to disable the submit button when it is submitted until the action failed or succeeded to prevent a form being submitted multiple times with the same data. I could have a I also tried using The documentation doesn't mention anything about action's loading state, which for me is a basic feature... So I must be missing something in this "loader/action" paradigm. It seems not possible that there's no built-in way to display a "Loading..." text while a form is being submitted... |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
You want the https://remix.run/docs/en/main/hooks/use-navigation const navigation = useNavigation()
return (
<Form method="post">
<button disabled={navigation.state === 'submitting'}>Submit</button>
</Form>
) |
Beta Was this translation helpful? Give feedback.
-
What if you're using fetcher instead? |
Beta Was this translation helpful? Give feedback.
You want the
useNavigation
hook. This returns the current navigation state, including form submissions. It also has the pendingformData
, for optimistic UI.https://remix.run/docs/en/main/hooks/use-navigation