question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

useFetcher() submit doesn't work with an object of type FormData

See original GitHub issue

What version of Remix are you using?

1.1.3

Steps to Reproduce

  1. Create a Form component
  2. onSubmit get the form element and const formData = new FormData(form);
  3. Then add anything formData.set('hello', 'world');
  4. 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:closed
  • Created a year ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
FrecksterGITcommented, Apr 14, 2022

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 to fetcher.submit(formData, { method: "post" }) should do the trick.

2reactions
Jaikantcommented, Apr 12, 2022

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found