建议的方式是什么:
props
中包含的数据发送事件react-router
使用redux-form
成功提交异步表单?
答案 0 :(得分:0)
我设置了一个回调函数,当调度交付函数时调用该函数:
<强>组件强>
onSubmit() {
const { userEmail, userPassword } = this.props;
this.props.loginUser({ userEmail, userPassword }, () => {
this.props.history.push('/dashboard');
});
}
<强>动作强>
export const loginUser = ({ userEmail, userPassword }, callback) => {
return(dispatch) => {
dispatch({ type: LOGIN_USER });
auth.signInWithEmailAndPassword(userEmail, userPassword)
.then(
user => {
loginUserSuccess(dispatch, user);
},
error => {
loginUserFail(dispatch, error.message);
}
)
redirectFunction(callback);
}
}
// Helper functions
const loginUserSuccess = (dispatch, user) => {
dispatch({
type: LOGIN_USER_SUCCESS,
payload: user
});
};
const loginUserFail = (dispatch, error) => {
dispatch({
type: LOGIN_USER_FAIL,
error: error
});
};
<强>减速器强>
case LOGIN_USER:
return { ...state, loading: true, error: '' };
case LOGIN_USER_SUCCESS:
console.log(action.payload);
return { ...state, ...INITIAL_STATE, user: action.payload, loggedIn: true };
case LOGIN_USER_FAIL:
return { ...state, error: action.error };
答案 1 :(得分:0)
通过在redux-form
回调onSubmitSuccess
/ onSubmitFailure
内部调度和重定向来管理解决方法。