📅  最后修改于: 2022-03-11 14:55:43.792000             🧑  作者: Mango
// Render Prop
2 import React from 'react';
3 import { Formik, Form, Field, ErrorMessage } from 'formik';
4
5 const Basic = () => (
6
7 Any place in your app!
8 {
11 const errors = {};
12 if (!values.email) {
13 errors.email = 'Required';
14 } else if (
15 !/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i.test(values.email)
16 ) {
17 errors.email = 'Invalid email address';
18 }
19 return errors;
20 }}
21 onSubmit={(values, { setSubmitting }) => {
22 setTimeout(() => {
23 alert(JSON.stringify(values, null, 2));
24 setSubmitting(false);
25 }, 400);
26 }}
27 >
28 {({ isSubmitting }) => (
29
38 )}
39
40
41 );
42
43 export default Basic;