Created
May 31, 2020 15:55
-
-
Save torbensky/bb92a54c1ca32b9cdbd09725d4c7b8e6 to your computer and use it in GitHub Desktop.
A typical React pattern for handling an event when you need to prevent default
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function MyForm(props){ | |
const handleSubmit = (event) => { | |
if(event){ | |
event.preventDefault() | |
} | |
props.onSubmit() // <== This is all I really want to do!!! | |
} | |
return <form onSubmit={handleSubmit}> | |
<!-- ... ---> | |
</form> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment