Selvin
Selvin

Reputation: 815

Redux call function and dispatch type in same function

I have a redux actions for sessiontimeout and logout. When Sessiontimeout called, Internally calling the logout function.

It did not work also SESSIONTIMEOUT action type not dispatched.

How I suppose to call logout in Sessiontimeout and dispatch both SESSIONTIMEOUT and LOGOUT

export function sessionTimeOut(){
    return (dispatch) => {
    dispatch({
        type: ACTIONTYPES.SESSIONTIMEOUT
    })
    }
    logout()
}

export function logout(){
    history.push('/')
    return { 
        type: ACTIONTYPES.LOGOUT 
    }
}

Upvotes: 1

Views: 48

Answers (1)

CodeZombie
CodeZombie

Reputation: 2087

Just dispatch logout() right after the SESSIONTIMEOUT action.

  export function sessionTimeOut(){
        return (dispatch) => {
        dispatch({
            type: ACTIONTYPES.SESSIONTIMEOUT
        });
        dispatch(logout());
        } 
    }

Upvotes: 1

Related Questions