I have a component that looks like this:
const App = (): ReactElement => {
const submitFeedbackHandler = (e: FormEvent): void => {
e.preventDefault();
// ...
}
return <>
<form onSubmit={submitFeedbackHandler}>
// ...
<button type='submit'>Submit</button>
</form>
</>
}
Problem is, no matter how I try to call submitFeedbackHandler from onSubmit it doesn't work. I tried onSubmit={(e) => submitFeedbackHandler(e)}, but no luck either. How can I get this to work so that I can do e.preventDefault()?
FormEvent&ReactElementimported?submitFeedbackHandleris just not called at all when the form submits.requiredto some inputs in the form. Oddly enough, this stopsonSubmitcompletely from being called. Even simply calling() => console.log('onSubmit!')didn't work, so I removed all the required tags from the inputs within the forms and it works fine now. I'll do validation of empty fields myself in that case instead of relying on therequiredtag on inputs.