Skip to content

Instantly share code, notes, and snippets.

@torbensky
Created May 31, 2020 15:55
Show Gist options
  • Save torbensky/bb92a54c1ca32b9cdbd09725d4c7b8e6 to your computer and use it in GitHub Desktop.
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
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