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

Have to set stringifyAllValues: false else all strings are double quoted #77

Closed
vrn-hkz opened this issue Feb 11, 2024 · 2 comments
Closed

Comments

@vrn-hkz
Copy link

vrn-hkz commented Feb 11, 2024

Because of this line in createFormData(data: T, stringifyAll = true) in ./utilities/index.ts

 if (stringifyAll) {
        formData.append(key, JSON.stringify(value)); // <---- This double quotes everything
      } else {
        formData.append(
          key,
          typeof value === "string" ? value : JSON.stringify(value),
        );
      }

So when accessing FormData in backend with formData.get('email') the result is "/"x@x.com/"" with double quoted string. What can be the workaround for this?

Currently I am setting stringifyAllValues: false and coercing all to strings in my zod schema.

@AlemTuzlak
Copy link
Contributor

@vrn-hkz this is the intended behavior, if you're interested in why this is done you can find a detailed explanation here:
react-hook-form/react-hook-form#11061 (comment)
I stringify it so I can preserve the original types and easily parse back to original values, you can use the "false" option to do that yourself obviously but then you would have to convert everything back manually, eg string number => number, string boolean => boolean

@vrn-hkz
Copy link
Author

vrn-hkz commented Feb 13, 2024

Ok thanks for the feeback!

@vrn-hkz vrn-hkz closed this as completed Feb 13, 2024
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

2 participants