如果我使用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
不行我错了?我无法理解
答案 0 :(得分:0)
问题(我不明白为什么!)const&#34; action&#34;
的名称export const _action_ = {...}
export const actionAuth = bindActionCreators(_action_, store.dispatch);
//now work fine!!!