Skip to content

Instantly share code, notes, and snippets.

@0xHexE
Created May 2, 2020 17:32
Show Gist options
  • Save 0xHexE/9bd25e3109c6f1b3355d1c97f0d36783 to your computer and use it in GitHub Desktop.
Save 0xHexE/9bd25e3109c6f1b3355d1c97f0d36783 to your computer and use it in GitHub Desktop.
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