Formik's Validation Schema As A Function
const MyComponent = withFormik({
// ...
validationSchema: yup.object().shape({
email: yup.string().required(),
feedback: yup.string().required(),
}),
// ...
})(MyForm);const MyComponent = withFormik({
// ...
validationSchema: (props) => {
let emailSchema;
if(props.allowAnonymous) {
emailSchema = yup.string();
} else {
emailSchema = yup.string().required();
}
return yup.object().shape({
email: emailSchema,
feedback: yup.string().required(),
});
},
// ...
})(MyForm);Last updated