提交后立即调用Redux表单UPDATE_SYNC_ERRORS

时间:2018-11-25 14:03:29

标签: reactjs redux react-redux redux-form react-redux-form

我使用Redux Form制作了一个登录表单,提交表单时,我发出了POST请求以验证电子邮件和密码。如果组合不正确,我会抛出一个新的SubmissionError,但是Redux Form会通过UPDATE_SYNC_ERRORS调用立即删除此SubmissionError。

我的LoginForm组件:

const LoginForm = ({ error, handleSubmit, authenticateUser }) => ( 
    <form onSubmit={handleSubmit(authenticateUser)}>
        <Field 
            name="email"
            component={RenderField}
            type="email"
            label="email"
            validate={[required, minLength(3), email]}
        />
        <Field 
            name="password"
            component={RenderField}
            type="password"
            label="password"
            validate={[required]}
        />
        {error && <strong>{error}</strong>}
        <div className="login__action__container">
            <button className="login__submit" type="submit">Submit</button>
            <NavLink className="login__link" to="/register">Or register</NavLink>
        </div>
    </form>
)

AuthenticateUser操作:

export const authenticateUser = values => dispatch => {
return axios.post('./api/user/login', {
    email: values.email,
    password: values.password
})
.then((response) => {
     // Does stuff
})
.catch((error) => {
    throw new SubmissionError({_error: error.response.data.error})
})

Image showcasing the Redux State and actions

最近几个小时我一直在进行错误修复,但是仍然没有结果。有人有金提示吗?预先感谢!

0 个答案:

没有答案