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

TypeError when calling handleSubmit in react-native #376

Closed
emily-curry opened this issue Jan 25, 2018 · 11 comments
Closed

TypeError when calling handleSubmit in react-native #376

emily-curry opened this issue Jan 25, 2018 · 11 comments

Comments

@emily-curry
Copy link

emily-curry commented Jan 25, 2018

Bug

Current Behavior

The recommended usage of formik in react native is: <Button onPress={props.handleSubmit} />. However, when using typescript, the type of event that handleSubmit accepts is different than what react-native's onPress generates.

Desired Behavior

Formik's handleSubmit should take a GestureResponderEvent in addition to React.FormEvent<HTMLFormElement>.

Suggested Solutions

This branch fixes this issue: https://github.com/Shurelia/formik/tree/handleSubmit-fix
Unfortunately, there is a typings conflict between @types/node and @types/react-native which prevents the build. Since the only type used from node was process, I've manually declared that as any and removed @types/node. Not an elegant solution, and I'd be open to working on it more if the maintainers are okay with removing @types/node from the project (and perhaps manually declaring process?).

Info

  • Formik Version: 0.10.5
  • OS: Windows 10
  • Node Version: 9.3.0
  • Package Manager and version: yarn 1.3.2
  • Typescript: 2.6.2
  • react: 16.2.0
  • react-native: 0.51.0
@emily-curry emily-curry changed the title TypeError when handling TypeError when calling handleSubmit in react-native Jan 25, 2018
@jaredpalmer
Copy link
Owner

Yeah this is legit. Hmmmmm. I think it may be time for Formik-native. In the mean time you can call submitForm()

@jaredpalmer
Copy link
Owner

I got stuck there too when trying to support React Native and TypeScript. I’m cool with dropping types/node if this works.

@emily-curry
Copy link
Author

Thanks for the tip on submitForm()! I put in a PR anyways (#379), as it seemed an easier fix than writing new documentation to explain why submitForm should be called instead.

As a side note, I'm really digging this library. Thanks for all the hard work! This has solved a lot of the issues I was having with redux-form, and the ease of integration with react native has made it a joy to work with.

@brianjd
Copy link

brianjd commented Jan 23, 2019

I see #379 was backed out (Re: #421). What is the current solution?

@wsdt
Copy link

wsdt commented Feb 25, 2019

For all coming here: The issue seems to be still open.
If you simply want to remove the warning you can cast your object. It's by far not the cleanest solution, but it's better than nothing.

onPress={handleSubmit as any}

@vitalyiegorov
Copy link

@jaredpalmer Any valid solution for correct typing in react-native?

@ianmartorell
Copy link

TypeScript is supported and React Native is supported but both at the same time aren't? 🤔

@patgoley-tts
Copy link

Any update on this issue? This makes it feel like React Native was largely an afterthought for Formik and not officially supported. Casting things to any is not a solution and can easily lead to bugs in the future.

@Alek5andr
Copy link

Still is the issue.
"formik": "^2.2.9",
"react-native": "0.70.5"

@macszl
Copy link

macszl commented Apr 25, 2023

I can confirm that this is still an issue.

@chulanovskyi-bs
Copy link

wondering why this issue was closed 👀 the problem, obviously, still hitting us badly with inability of normalizing the types properly.

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

10 participants