Why onSubmit is a required prop? #3097
-
|
Hi, Is there a way to avoid using I get the following error: I understand the reason why How do you manage this situation? Thank you |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
|
I just pass an empty function to be explicit about what happens on submit: In HTML5 a form's default action is to submit a GET request to the current page (99% of the time, not what you want, and can be a security risk if you aren't aware this will happen). Unfortunately, in React Native that doesn't mean anything. In React Native the default action is nothing because there is no Alternatively we could do one of the following to remove the requirement to pass onSubmit, but I have a feeling it would be a debate to determine which one makes more sense:
|
Beta Was this translation helpful? Give feedback.
I just pass an empty function to be explicit about what happens on submit:
onSubmit={() => {}}.In HTML5 a form's default action is to submit a GET request to the current page (99% of the time, not what you want, and can be a security risk if you aren't aware this will happen). Unfortunately, in React Native that doesn't mean anything. In React Native the default action is nothing because there is no
<form />element. Formik works in both of these places and would have different behaviors without an onSubmit, so we strongly recommend (read, require in TypeScript) that you pass an onSubmit. Note that it technically doesn't have different behaviors because we do not fall back to form.submit…