目前我正在尝试在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 {};
}
}
答案 0 :(得分:0)
你可以试试这个:
import { connect } from 'react-redux' ;
import { reduxForm } from 'redux-form';
...
export default connect(mapStateToProps, mapDispatchToProps)(reduxForm({
form: 'signInForm',
validate
})(SignIn));