Created
May 2, 2020 17:32
-
-
Save 0xHexE/9bd25e3109c6f1b3355d1c97f0d36783 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function ExampleForm() { | |
const [intitialValue, setIntitalValue] = useState(null); | |
useEffect(() => { | |
setTimeout(() => { | |
setIntitalValue({ | |
email: 'This is my async email', | |
}); | |
}, 3000); | |
}, []); | |
if (intitialValue === null) { | |
return null; | |
} | |
return ( | |
<Formik | |
validateOnChange={false} | |
initialValues={intitialValue} | |
validate={(values) => { | |
const errors = {}; | |
if (!values.email) { | |
errors.email = 'Enter email address'; | |
} else if (values.email.indexOf('@') === -1) { | |
errors.email = 'Invalid email address'; | |
} | |
return errors; | |
}} | |
onSubmit={(values, actions) => { | |
actions.setSubmitting(false); | |
}}> | |
<BaseFormikField | |
name="email" | |
id="email" | |
labelText="Email" | |
placeholder="Email" | |
renderField={TextInput} | |
/> | |
</Formik> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment