useFetcher() submit doesn't work with an object of type FormData
See original GitHub issueWhat version of Remix are you using?
1.1.3
Steps to Reproduce
- Create a Form component
onSubmit
get the form element andconst formData = new FormData(form);
- Then add anything
formData.set('hello', 'world');
- Then
fetcher.submit(formData)
And you’ll notice we never arrive in the action handler. If I pass the form element directly to submit
, then it works as expected.
Expected Behavior
Since the submit function’s signature accepts a FormData object, I expect it to call my action handler.
Actual Behavior
Does nothing. No error. No logs. All I see is that the fetcher.state
goes to submitting
and then goes back to idle
without doing anything.
Issue Analytics
- State:
- Created a year ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Remix useSubmit arbitrary data - javascript - Stack Overflow
I have form elements with some static values that have disabled/readonly attributes, which means their value will be null on form submission.
Read more >Using FormData Objects - Web APIs | MDN
The FormData object lets you compile a set of key/value pairs to send using XMLHttpRequest. It is primarily intended for use in sending...
Read more >Data Writes - Remix
When there is a pending form submission, Remix will give you the serialized version of the form as a FormData object. You'll be...
Read more >useFetcher v6.6.1 - React Router
fetch data not associated with UI routes (popovers, dynamic forms, etc.) submit data to actions without navigating (shared components like a newsletter sign...
Read more >Mastering Remix Forms - Better Programming
We can host that on the edge itself and delegate the action to wherever we want. How would we get the user-submitted info?...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The action method is only called for POST requests. In your error report you use
fetcher.submit(formData)
which results in a GET-Request. Changing it tofetcher.submit(formData, { method: "post" })
should do the trick.@silvenon understood! I shall probably wait for @kemicofa to provide more information. Just in case there are some boundary cases I didn’t cover in my repro.