Skip to content

Instantly share code, notes, and snippets.

@maruware
Created November 28, 2019 05:08
Show Gist options
  • Save maruware/bb34ad57d8fa962f65d6af5f6a1906cf to your computer and use it in GitHub Desktop.
Save maruware/bb34ad57d8fa962f65d6af5f6a1906cf to your computer and use it in GitHub Desktop.
form with preventDefault to default
import React, { useCallback } from 'react'
export interface FormProps
extends React.DetailedHTMLProps<
React.FormHTMLAttributes<HTMLFormElement>,
HTMLFormElement
> {}
export const Form: React.FC<FormProps> = ({ onSubmit, ...rest }) => {
const handleSubmit = useCallback(
(e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault()
onSubmit(e)
},
[onSubmit]
)
return <form {...rest} onSubmit={handleSubmit} />
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment