Prevent redirect on form submit
Answered
Rojoss posted this in #help-forum
RojossOP
When I submit a form there is a redirect happening.
I'm trying to cancel the event but that's not working.
I just want to run some client side code when the form is submitted.
I'm trying to cancel the event but that's not working.
I just want to run some client side code when the form is submitted.
const handleSubmit = async(e: FormEvent) => {
e.preventDefault();
console.log('form submitted')
}<form onSubmit={handleSubmit}>
<Button type='submit'>Save Changes</Button>
</form>5 Replies
American Chinchilla
@Rojoss probably because the function is async
Answer
An idea is simply to move that async into a seperate function
RojossOP
Alright thanks!
Havana
Just use 'react-hook-form' instead of going full vanilla. It offers you more than just cancelling the event