diff --git a/src/components/FORM/formik.jsx b/src/components/FORM/formik.jsx new file mode 100644 index 0000000..b689f6d --- /dev/null +++ b/src/components/FORM/formik.jsx @@ -0,0 +1,64 @@ + +import React from 'react' + + +// import * as yup from 'yup'; +import { useFormik } from "formik"; + + +export default function Signup() { + + const formik = useFormik({ + initialValues :{ + name : '', + email : '', + password : '' + }, + onSubmit : (values,{resetForm})=>{ + console.log(values); + resetForm({values: ""}) + } + }) + + + return ( +
+

User Signup

+
+
+ + +
+
+ + +
+
+ + +
+ +
+ + +
+ ) +} diff --git a/src/components/FORM/yupFormik.jsx b/src/components/FORM/yupFormik.jsx new file mode 100644 index 0000000..2001312 --- /dev/null +++ b/src/components/FORM/yupFormik.jsx @@ -0,0 +1,77 @@ + +import React from 'react' + + +import * as yup from 'yup'; +import { useFormik } from "formik"; + + +export default function Signup() { + + const formik = useFormik({ + initialValues :{ + name : '', + email : '', + password : '' + }, + validationSchema: yup.object({ + name: yup.string().min(2, "name must have atleast 2 characters ").required(), + email: yup.string().email().required(), + password: yup.string().min(6, "password must have atleast 6 characters ").required(), + }), + onSubmit : (values,{resetForm})=>{ + console.log(values); + resetForm({values: ""}) + } + }) + + const renderNameError = formik.touched.name && formik.errors.name && {formik.errors.name} + const renderEmailError = formik.touched.email && formik.errors.email && {formik.errors.email} + const renderPasswordError = formik.touched.password && formik.errors.password && {formik.errors.password} + + + const renderForm =
+
+ + + {renderNameError} +
+
+ + + {renderEmailError} +
+
+ + + {renderPasswordError} +
+ +
+ + return ( +
+

User Signup

+ {renderForm} + +
+ ) +}