0

I've had this bug for days now, when I dispatch an action, store.getState() shows the updated state, but when using mapStateToProps in other component, the updated state is lost, and what is shown is the default state.

Console output

On Form Submission

const handleLoginSubmit = (e) =>{
    e.preventDefault();
    let gottenName = name.length > 1;
    let gottenPassword = password.length > 1;

    if (gottenName && gottenPassword){
        //HERE
        props.dispatch({type:"L", payload:' name '})

    }
}



`store.getState()` Update accordingly

const store = createStore(rootReducer);

store.subscribe(()=>{
  let getName = store.getState();
  if (getName.name !== ''){
    setLoginSuccess(true);
  }
  console.log("HI",store.getState());
})

When I try to view the update data in other components, it only shows the default state:

useEffect(()=>{
    console.log("happy Birth :)",props.name);
});
const mapStateToProps = (state)=>({
   name: state
});
export default connect(mapStateToProps)(LeftSideTop);
Aryan Beezadhur
  • 4,503
  • 4
  • 21
  • 42

0 Answers0