Created
November 28, 2019 05:08
-
-
Save maruware/bb34ad57d8fa962f65d6af5f6a1906cf to your computer and use it in GitHub Desktop.
form with preventDefault to default
This file contains hidden or 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
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