Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

change state in redux store depending on route

I’m trying to dispatch to store depending on which path I’m in, but it always run through the whole switch statement and dispatch the last case: (in my app.js).

const location = useLocation();
const dis = useDispatch();
 switch(location.path){
case "/":
  dis(nextStep(0))
case "/Payment-method":
  dis(nextStep(1))
  case "/Confirm":
    dis(nextStep(2))
default: console.log("error")
}

no matter what, i get that the state is always 2.
As shown in redux:
enter image description here

Each NEXT_STEP is in this order: 0, 1, 2, 0, 1, 2 – which in turn leaves the state (stepUpdate) at 2.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The reason i want to do this is to keep track of which page number i’m in. This value in turn will be used in my stepper – which takes an integer value.

>Solution :

Can you try first with if else statement, this help to figure out the source of the problem
Or try to add Break; at the end of each case

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading