Skip to content

Instantly share code, notes, and snippets.

@whoisryosuke
Created April 30, 2021 18:01
Show Gist options
  • Select an option

  • Save whoisryosuke/32ff8ff12e04ab8443c8250c5df18a3b to your computer and use it in GitHub Desktop.

Select an option

Save whoisryosuke/32ff8ff12e04ab8443c8250c5df18a3b to your computer and use it in GitHub Desktop.
JS / Yup - Example of Yup form validation - @see: https://github.com/jquense/yup
import * as yup from 'yup';
// In your React component...
const checkFormData = async () => {
let schema = yup.object().shape({
testName: yup.string().required(),
name: yup.string().required(),
email: yup.string().email().required(),
});
// Put your React state in here
// Returns true or false if form is valid or not
const testPassed = await schema.isValid(this.state);
return testPassed
}
const isValid = checkFormData();
if(isValid) {
// Test passed!
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment