[英]redux bindActionCreators any action is dispached
after 20 hours of test i can not understand where i mistake. 经过20个小时的测试,我无法理解我的错误之处。
all work fine if i use a storeredux dispacth, but now i will use action with bindActionCreators 如果我使用storeredux Dispacth,则一切正常,但现在我将对bindActionCreators使用action
this is my 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);
the component 组件
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)
in component or in action if i use store.dispatch i see work all fine, but not work if i try use actionAuth.login 如果我使用store.dispatch,则在组件中还是在动作中,我都可以正常工作,但如果尝试使用actionAuth.login,则无法正常工作
where i mistake?i can not understand 我在哪里弄错了?我听不懂
the problem (i not understand why!) the name of const "action" 问题(我不明白为什么!)const“ action”的名称
export const _action_ = {...}
export const actionAuth = bindActionCreators(_action_, store.dispatch);
//now work fine!!!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.