React-Redux操作分派问题?

问题描述 投票:0回答:1

这是下面的代码,我无法调用userLoginRequest。 userLoginRequest只是对用户进行身份验证,我无法为userLoginRequest派遣acion。 我是新手,可以进行反应和反应-redux,所以请指导我。

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);
reactjs redux react-redux redux-saga
1个回答
0
投票

您已经破坏了动作模块

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

或不破坏行动

import * as actions from './actions';

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

© www.soinside.com 2019 - 2024. All rights reserved.