import React, { useState } from 'react'; import { Field, Form, Formik } from 'formik'; import * as Yup from 'yup'; import axios from 'axios'; import 'bootstrap/dist/css/bootstrap.css'; import { Link, Redirect } from 'react-router-dom'; function Find() { const [state, setState] = useState(false); if (state) { return ; } return (
{ axios({ method: 'post', url: '/login/find', data: values, }).then(res => { if (res.status === 404) return alert(res.data.error) localStorage.setItem('id', res.data.users._id); setState(true); }) .catch(err => { alert(err.error) }); console.log(values); setTimeout(() => { setSubmitting(false); }, 400); // finish the cycle in handler }} > {({ errors, touched, handleSubmit, getFieldProps, // contain values, handleChange, handleBlur isSubmitting, }) => (
{touched.id && errors.id ? (
{errors.id}
) : null}
{touched.answer && errors.answer ? (
{errors.answer}
) : null}
)}
); } // const withFormik = Formik({ // mapPropsToValues: () => ({ color: '' }), // validationSchema: Yup.object().shape({ // color: Yup.string().required('Color is required!'), // }), // handleSubmit: (values, { setSubmitting }) => { // setTimeout(() => { // alert(JSON.stringify(values, null, 2)); // setSubmitting(false); // }, 1000); // }, // displayName: 'BasicForm', // helps with React DevTools // }); // const MyForm = props => { // const { // values, // touched, // errors, // dirty, // isSubmitting, // handleChange, // handleBlur, // handleSubmit, // handleReset, // } = props; // return ( //
// // // {errors.color && // touched.color && //
// {errors.color} //
} // // // // // ); // }; export default Find;