Created
November 26, 2019 17:45
-
-
Save i-oliva/af5d673318dc0e698994bbcaeb12e80e to your computer and use it in GitHub Desktop.
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
import { Formik } from "formik"; | |
import React from "react"; | |
import * as yup from "yup"; | |
type SignInForm = { | |
email: string; | |
password: string; | |
}; | |
type SignInProps = { | |
onSubmit: ({ email, password }: SignInForm) => void; | |
Form: React.ElementType; | |
validationSchema: yup.ObjectSchema< | |
yup.Shape< | |
object, | |
{ | |
email: string; | |
password: string; | |
} | |
> | |
>; | |
}; | |
export default ({ onSubmit, Form, validationSchema }: SignInProps) => { | |
return ( | |
<Formik | |
initialValues={{ email: "", password: "" }} | |
validationSchema={validationSchema} | |
onSubmit={values => { | |
const { email, password } = values; | |
onSubmit({ email, password }); | |
}} | |
> | |
{({ handleChange, handleBlur, handleSubmit, values }) => { | |
return ( | |
<Form | |
handleChange={handleChange} | |
handleBlur={handleBlur} | |
handleSubmit={handleSubmit} | |
values={values} | |
/> | |
); | |
}} | |
</Formik> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment