目前我正在尝试在react / redux中调度一些动作,我也在使用redux形式 . 如何在react-redux连接函数中实现redux表单?
派遣功能:
const mapDispatchToProps = (dispatch) => {
return{
authUser: () => {
dispatch(authUser());
},
signIn: () => {
dispatch(authUser());
}
}
}
然后使用react-redux连接功能:
export default reduxForm({
validate, form: 'signInForm'})
(connect(mapStateToProps, mapDispatchToProps) (SignIn))
将signIn函数传递给mapDispatchToProps时,表单会停止提交吗?
mapStateToProps函数:
function mapStateToProps(state){
return {
SignInDetails: state.SignInDetails,
isAuthenticated: state.isAuthenticated
}
}
signIn Reducer:
import _ from 'lodash';
const SIGN_IN_FULFILLED = 'SIGN_IN_FULFILLED';
export default function(state, action){
//eslint-disable-next-line
switch (action.type) {
case SIGN_IN_FULFILLED:
return _.mapKeys(action.payload.data, 'id');
default:
return {};
}
}
1 回答
你可以试试这个: