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.
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.
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;
.
So instead of:
return
[{
fname: action.fname,
lname: action.lname,
}]
Do this instead:
return [{
fname: action.fname,
lname: action.lname,
}];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.