I am using formik and I am wondering how to use async/await with onSubmit(我正在使用formik,我想知道如何在onSubmit中使用异步/等待)
<Formik
initialValues={{ email: '' }}
onSubmit={(values, { setSubmitting }) => {
// how to do async/await here.
}}
validationSchema={Yup.object().shape({
email: Yup.string()
.email()
.required('Required'),
})}
>
{props => {
const {
values,
touched,
errors,
dirty,
isSubmitting,
handleChange,
handleBlur,
handleSubmit,
handleReset,
} = props;
return (
<form onSubmit={handleSubmit}>
<label htmlFor="email" style={{ display: 'block' }}>
Email
</label>
<input
id="email"
placeholder="Enter your email"
type="text"
value={values.email}
onChange={handleChange}
onBlur={handleBlur}
className={
errors.email && touched.email ? 'text-input error' : 'text-input'
}
/>
{errors.email &&
touched.email && <div className="input-feedback">{errors.email}</div>}
<button
type="button"
className="outline"
onClick={handleReset}
disabled={!dirty || isSubmitting}
>
Reset
</button>
<button type="submit" disabled={isSubmitting}>
Submit
</button>
<DisplayFormikState {...props} />
</form>
);
}}
</Formik>
ask by chobo2 translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…