Skip to content

Instantly share code, notes, and snippets.

@cybercris
Last active March 30, 2020 15:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cybercris/68c61a7ff8408215b25e88dc4e4740b9 to your computer and use it in GitHub Desktop.
Save cybercris/68c61a7ff8408215b25e88dc4e4740b9 to your computer and use it in GitHub Desktop.
optionalSchema
const optionalRequiredSchema = yup.object().shape({
optionalObject: yup.lazy(value => {
if (value !== undefined) {
yup.mixed().notRequired();
}
return yup.object().shape({
otherData: yup.string().required()
});
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment