I'm making input validations with formik
, when my form is filled he calls the function handleSubmit
, but this function is outside my hook component, so I can't call dispatchs
.
How I can put the handleSubmit
logic inside my hook component?
This is my code:
const schema = Yup.object().shape({
email: Yup.string().email('Email don't have a valid format').required('Fill the email!'),
password: Yup.string().required('Fill the password')
})
const enhanceWithFormik = withFormik({
mapPropsToValues: () =>
({
email: '', password: ''
}),
handleSubmit: values => {
registerFirstData(values)
},
validateOnMount: false,
validateOnChange: true,
validateOnBlur: true,
displayName: 'RegistrarForm',
validationSchema: schema
})
const Register = props => {
const {
values,
touched,
errors,
isSubmitting,
handleChange,
handleBlur,
handleSubmit
} = props;
return (
<form onSubmit={handleSubmit} className={classes.form} noValidate>
...
</form>
)
}
export default enhanceWithFormik(Register);
What i tried:
const Register = props => {
const { enqueueSnackbar } = useSnackbar();
const handleSubmit = values => {
console.log(values)
}
const {
values,
touched,
errors,
isSubmitting,
handleChange,
handleBlur,
// Removed handleSubmit from here
} = props;
return (
<Form onSubmit={handleSubmit} className={classes.form} noValidate>
...
)
But this way my page is reloaded when i click in my submit button