如何将redux表单添加到我的调度函数中?

时间:2017-10-26 08:58:03

标签: javascript forms reactjs redux redux-form

目前我正在尝试在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 个答案:

答案 0 :(得分:0)

你可以试试这个:

import { connect } from 'react-redux' ;
import { reduxForm } from 'redux-form';

...




export default connect(mapStateToProps, mapDispatchToProps)(reduxForm({
      form: 'signInForm',
      validate
})(SignIn));