import React, { useState } from 'react'; import { 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 Change(props) { const [state, setState] = useState(); if (state) { return ; } console.log(props) return (
{ axios.put(`/users/change/${props.location.state.id}`, { ...values }, ) .then(res => { console.log(res.data); if (res.status === 404) return alert(res.data.error) alert("회원정보가 수정되었습니다!") setState(true); }) .catch(err => { alert(err.error) }); setTimeout(() => { setSubmitting(false); }, 400); // finish the cycle in handler }} > {({ errors, touched, handleSubmit, getFieldProps, // contain values, handleChange, handleBlur isSubmitting, }) => (
{touched.password && errors.password ? (
{errors.password} ) : null}
{touched.password2 && errors.password2 ? (
{errors.password2}
) : null}
)}
); } export default Change;