Last active
April 24, 2020 03:07
-
-
Save kilgarenone/f6945ff3d67756df5338b35d9f8bd0b3 to your computer and use it in GitHub Desktop.
yup in a redux-form component
This file contains 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
import * as React from 'react' | |
import * as Yup from 'yup' | |
import { Field, reduxForm } from 'redux-form' | |
import validator from './validator.ts' | |
// more imports | |
class YourClass extends React.Component<Props> { | |
// stuffs | |
render() { | |
return ( | |
<form onSubmit={this.onSubmit}> | |
<Field | |
name={'email'} | |
component={TextInput} | |
placeholder={'abc@example.com'} | |
/> | |
</form> | |
) | |
} | |
} | |
const schema = Yup.object().shape({ | |
email: Yup | |
.string() | |
.email('Invalid email address') | |
.required('Email address is required') | |
}) | |
export default reduxForm({ | |
form: 'yourFormName', | |
asyncValidate: validator(schema) | |
})(YourClass) |
Whats inside the validator.ts file, its shows validator error when i do this ?
Hi. The content of validator.ts
can be found here https://gist.github.com/kilgarenone/cef4d29ffdf1381bef30d2333372f7c7#file-validator-ts
I also talked about this whole thing in this medium post https://medium.com/@kilgarenone/use-yup-with-redux-form-684d6c23ab41
Good luck!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Whats inside the validator.ts file, its shows validator error when i do this ?