score:0

Accepted answer

storing the selected value in redux store or component state itself would be better choice for this, but you can also

  • store it in localstorage
  • store it in sessionstorage
  • when redirecting the user back, pass it as a url parameter

if you're using any one of these methods, in formcomponent you can check if the value exists and perform operations accordingly.

example code

orderlistcomponent

let handlechange = (value) => {
  localstorage.orderlistvalue = value
}

this will replace any existing value as well.., use your brain here.

formcomponent

if ( localstorage.orderlistvalue ) {
  console.log('yay.. we have data');
} else {
 // ask the user to select the list first.
}

score:1

the best way is to have state manager. redux state will solve it elegantly. though as random user mentioned in his answer; localstorage/sessionstorage can be used to do this.

but passing the values by url will be tricky when there are too many items selected for order.

the state can be changed so that having anything in state will give consistent output at orderlistcompoennt.

you can have order state and push the items to that state. and then redirect the user to orderlistcomponent rather than doing router.push('xxxx').

orderlistcomponent will watch the state and show the items accordingly.

the formcomponent will also watch the order state for marking the currently added items. with this way, there will not be any router.goback(); just the redirects by router.push

and when your app will be at formcomponent, order state will automatically be responsible to mark the items which are currently in order.


Related Query

More Query from same tag