[英]redux dispatch action and reducer with new state
I have actions like: 我有这样的行动:
export function login(){
my_login(function(response){
if(response.status == "ok"){
loginSuccess(response)
}
})
}
export function loginSuccess(response){
return dispatch => {
dispatch({ response, type: types.LOGIN });
console.log("dispatched");
console.log(getState()); ---> I want the updated state
router.transitionTo("/some_url");----> after this I want to route it to somewhere
};
}
When my login
action is called it again calls my_login
and then I am dispatching my loginSuccess
action. 当我的login
操作被调用时,它再次调用my_login
然后我将调度我的loginSuccess
操作。
I have a reducer like: 我有一个减速器,如:
const initialState = [
{
fname: null,
lname: false,
}
]
export default function login(state = initialState, action) {
switch (action.type) {
case LOGIN:
console.log("actions dude")
console.log(action)
return
[{
fname: action.fname,
lname: actin.lname,
}]
default:
return state
}
}
Here my state is not changing and I am not getting the getState()
value in action above. 这里我的状态没有改变,我没有获得上面的getState()
值。
I dont think my reducer is called and state is updated. 我不认为我的减速机被调用,状态更新。
Can anyone sugges me whats wrong in here ? 任何人都可以在这里向我提出错误吗?
我认为你丢失了dispatch(loginSuccess(response))
Beware of the bare return statement. 小心裸回报声明。 One of the known pitfalls of automatic semicolon insertion is that return
becomes return;
自动分号插入的一个已知缺陷是return
变为return;
. 。
So instead of: 所以代替:
return
[{
fname: action.fname,
lname: action.lname,
}]
Do this instead: 改为:
return [{
fname: action.fname,
lname: action.lname,
}];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.