簡體   English   中英

redux bindActionCreators分配了任何動作

[英]redux bindActionCreators any action is dispached

經過20個小時的測試,我無法理解我的錯誤之處。

如果我使用storeredux Dispacth,則一切正常,但現在我將對bindActionCreators使用action

這是我的行動

import {bindActionCreators} from "redux"
import store from "../Store/Store";
export const action = {
login:function(payload) {
    console.log("i'm here");
    return {
    type:"AUTH_LOGIN",
    payload
    }
    //this work!!
    // store.dispatch({
    //                 type:"AUTH_LOGIN",
    //                 payload
    //             })
    }
}
export const actionAuth = bindActionCreators(action, store.dispatch);

組件

class Login extends Component {
    login(type, username, password) {
        actionAuth.login({
                        typeauth:type,
                         username:username,
                         password:password
                     })
    }
    render(){
      return(<button onclick={()=>{this.login("ok","user,"pwd");}}>click</button>)
     }
  }

   const selector=createSelector(
    (state)=>{return state.auth},
(auth)=>{return auth.toJS()}
  );
  function mapStateToProps(state, props) {
    return {
      ...selector(state)
      }}
  export default connect(mapStateToProps)(Login)

如果我使用store.dispatch,則在組件中還是在動作中,我都可以正常工作,但如果嘗試使用actionAuth.login,則無法正常工作

我在哪里弄錯了?我聽不懂

問題(我不明白為什么!)const“ action”的名稱

export const _action_ = {...}
export const actionAuth = bindActionCreators(_action_, store.dispatch);
//now work fine!!!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM