React-Redux行动调度问题?

时间:2017-06-09 11:00:53

标签: reactjs redux react-redux redux-saga

这是下面的代码,我无法调用userLoginRequest。 userLoginRequest只是验证用户,我无法为userLoginRequest调度acion。我是新手做出反应并做出反应 - 所以请指导我。

import React, { PropTypes } from 'react';
import { connect } from 'react-redux';
import Helmet from 'react-helmet';
import { createStructuredSelector } from 'reselect';
import makeSelectLoginContainer from './selectors';
import Login from 'components/Login';
import { userLoginRequest } from './actions';


export class LoginContainer extends React.PureComponent { // eslint-disable-line react/prefer-stateless-function
  doLogin(username, password) {
    console.log('DoLogin', username, password);
  }
  render() {
    return (
      <div>
        <Login handleSubmit={this.doLogin}></Login>
      </div>
    );
  }
}

LoginContainer.propTypes = {
  userLoginRequest: PropTypes.func.isRequired,
};

const mapStateToProps = createStructuredSelector({
  LoginContainer: makeSelectLoginContainer(),
});


function mapDispatchToProps(dispatch) {
  return {
    userLoginRequest: (username, password) => dispatch(actions.userLoginRequest(username, password)),
  };
}

export default connect(mapStateToProps, mapDispatchToProps)(LoginContainer);

1 个答案:

答案 0 :(得分:0)

您已经解构了行动模块

userLoginRequest: (username, password) => dispatch(userLoginRequest(username, password)),

或不破坏行动

import * as actions from './actions';

当然,你需要在this.props.userLoginRequest方法中调用doLogin:)