Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useFetch post call inserts quotes when passed a string #360

Open
nibblesnbits opened this issue Jan 20, 2022 · 6 comments
Open

useFetch post call inserts quotes when passed a string #360

nibblesnbits opened this issue Jan 20, 2022 · 6 comments

Comments

@nibblesnbits
Copy link

Describe the bug
useFetch post call inserts quotes when passed a string.

⚠️ Make a Codesandbox ⚠️
Please click this to easily reproduce the bug.

To Reproduce
Steps to reproduce the behavior:

  1. Go to https://codesandbox.io/s/strange-wave-onbnw?file=/src/App.js
  2. Open devtools and observe network call to `/test'
  3. View request payload
  4. See that "test" is exctly that. The word "test" wrapped in quotes.

Expected behavior
I expect a string to be passed into the body of the request as a string, not wrapped in quotes.

@joaoarieira
Copy link

You need something like this?
await post("/test", {test: "test"});

@nibblesnbits
Copy link
Author

nibblesnbits commented Jan 21, 2022 via email

@joaoarieira
Copy link

I'm afraid I can't help you.
This should help:
https://use-http.com/#/?id=file-upload-formdata

@nibblesnbits
Copy link
Author

I've updated the sandbox. No, that link doesn't help, unfortunately because I'm not using FormData, I need to just pass a string. https://codesandbox.io/s/bold-stallman-xf6ko?file=/src/App.js

@csvan
Copy link

csvan commented Feb 13, 2024

This also breaks XML bodies, which are incorrectly formatted as strings rather than plain XML values. Sending the exact same body using native fetch works, but breaks when using the hook.

@csvan
Copy link

csvan commented Feb 13, 2024

I'm afraid I can't help you.

Doesn't this hook use the native fetch under the hood? If so, why is the default behaviour modified?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants