0

I Have the redux connected in my code

   loginAction(){
    console.log("dashboard login action");
    this.props.login("username","password")
    console.log("mapstate to props dashboard "+JSON.stringify(
        this.props.loginStatus));
}


const mapStateToProps = (state) => {
return {
    loginStatus:state.loginStatus
    
};

}

when I try to access this.props.loginStatus after calling the this.props.login("username","password") method,this becomes undefined. When i observed it is because it takes time to update the store. How to figure out when the store update is done by a callback or something,when the store updated i can get the this.props.loginStatus

export default function LoginReducer(state = initialstate, action) {
console.log("loginreducer calling =" + action.type + " " + JSON.stringify(
    action.payload));
switch (action.type) {

    case "USER_LOGIN":
        console.log("case USER_LOGIN");
        //axiox get auth url
        return Object.assign({}, state, action.payload)
    default:
        return state

}

}

attached is my reducer

4
  • Can we have the rest of the code please, we need to know where you are accessing this store Commented Aug 27, 2022 at 11:25
  • sure already added Commented Aug 28, 2022 at 7:05
  • Please note that you aren't waiting for the login action to complete, please check async await or add Promise response if you are using it inside this.props.login() already Commented Aug 29, 2022 at 12:25
  • Hasan Riza could you show me an example , basically it should happen from the reducer Commented Aug 31, 2022 at 10:54

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.