Skip to content

Instantly share code, notes, and snippets.

@maruware
Created November 28, 2019 05:08
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