I am using history object(passed from component to reducer) provided by react in my reducer to conditionally route to other pages while updating the state. I knew thats not how navigation must be handled. But its still working, Is the history.push() function async call as i am executing it before returning modified state in reducer. Can someone explain me why this works
const reducer = (state = initialState, action) => {
var stateClone = {...state};
switch(action.type)
{
case 'LogIn':
var user = state.users.filter((user) => user.userName === action.userName && user.password === action.password );
if(user.length > 0 )
{
var loggedInUser = {...user[0]};
stateClone.loggedInUser = loggedInUser;
action.history.push('/products');
return stateClone;
}
else {
alert('Wrong Credentials');
}
return state;
}
}