gpt4 book ai didi

javascript - redux bindActionCreators 任何操作都会被调度

转载 作者:行者123 更新时间:2023-11-28 03:43:24 25 4
gpt4 key购买 nike

经过 20 个小时的测试,我不明白我错在哪里。

如果我使用 storeredux dispacth,一切都可以正常工作,但现在我将使用带有 bindActionCreators 的操作

这是我的行动

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!!!

关于javascript - redux bindActionCreators 任何操作都会被调度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48722008/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com