redux-form: Errors not passed into onSubmitFail
errors in the onSubmitFail is not being populated for me. Am I doing something wrong or is this a bug??
import React from 'react';
import { Field, reduxForm, SubmissionError } from 'redux-form';
const Password = (props) => {
const { handleSubmit, submitting, error } = props;
const submit = () => Promise.reject(new Error('test'));
return (
<form onSubmit={handleSubmit(submit)}>
<div>
<label htmlFor="password">Password</label>
<Field name="password" component="input" type="password" placeholder="Password" />
</div>
<h1>{error}</h1>
<div>
<button type="submit" disabled={submitting}>Next</button>
</div>
</form>
);
};
export default reduxForm({
form: 'password',
onSubmitFail: (e) => {
console.log(e); // shows undefined
throw new SubmissionError({ _error: e.message });
},
})(Password);
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 15 (1 by maintainers)
Because this issue saw almost no activity for a few months, I’m closing it.
I had the same issue, error in props always give out undefined
Any updates on this issue?
You can use the third parameter passed to
onSubmitFail, it contains the original error. What I do is: