score:0
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.
Source: stackoverflow.com
Related Query
- How does react component pass value to the previous page component
- How can I redirect to another component in react and pass the state that I set in the previous component?
- How to re-render the component in react if useState does not change or hold the last value
- How to pass the return value of a function as a property to a react component
- How does prevState in new useState in React work ?? How does it store the value of previous state?
- How to pass a dynamic value from one component to the other in React
- In React typescript how to pass checkbox status from Sidebar component to MainContent component to refresh the page
- How to pass in a react component into another react component to transclude the first component's content?
- Does react re-render the component if it receives the same value in state
- How to pass the match when using render in Route component from react router (v4)
- How does React know the component is removed from the DOM?
- React router - pass api data to the linked component to open with a new page
- How to pass input value from child to parent component react
- How do I pass in the variant property of the material-ui TextField from a wrapping React component
- how to update a route in React Router without re-mounting the component in a single page app?
- I can not get the state from react router Link component using useLocation. So how can I pass it?
- How to check the value of a nested React component in a unit test with Enzyme and Jest
- How can I pass the original JSX markup to a component for display in the page as code?
- How to access the latest state value in the functional component in React
- React Hooks: how to prevent re-rendering the whole component when only the props.children value changes?
- How to render component as soon as the value stored in local in React
- How to pass input values from a child Form component to the state of its parent component for submission with react hooks?
- React router dom passing data from parent component to child router component does not pass the props.match
- How does the react `Router` component communicate with the `Route` component?
- How to take the input from a react component and pass the length of the input to another react component
- In React How to pass Id to another page class component
- How to pass a state to a Parent component if I have a button triggering the state in the 2nd Child in React
- How do I pass a prop to a react component yet not update that prop in the child when parent changes?
- How to make the pass a dynamic value to css class and cusmize in material UI in react
- How to pass the props value from the other sibling components in React JS
More Query from same tag
- typescript + react/redux: property "yyy" does not exist on type 'intrinsicattributes & intrinsicclassattributes
- MongoDB - How to Update or Insert object in array
- Show specific number of array objects (React)
- Using Material-UI's Autocomplete component with Formik
- Carousel Transitions not Responding
- How to query graphql in react typescript
- React - Changing state in context not rerendering DOM
- How to later use a method on a object that is stored in useState?
- how can i change color of font if value get change?
- How to create a dynamic input type component
- How to test componentWillReceiveProps method in react component
- React using forwardRef always update child component even using memo
- ReactiveAggregate() + collection.update() -> Error: Expected to find a document to change
- Displaying a Form From OnClick Button
- How to change component in another component when switching to another link?
- React 16.3 Context: expected a string (for built-in components) or a class/function (for composite components) but got: object
- Revalidate doesn't work on Vercel using NextJS
- load local jSON file in Reactjs without installing a localserver
- Rendering TopoJSON with react-leaflet
- React app : old version kept in cache until I inspect it
- React Flux store emit event not working
- React Synthetic Events Bubble Capture with Components
- how to map through API data when each data array is different
- How to handle/chain synchronous side effects that depend on another with React hooks
- Fetched Data to State
- Child Component does not refresh when List Array is updated
- Redux is able to set characters to an array however the remove action does not seem to reach the reducer
- In ReactJS, facing problem in rendering the data from an API due to its odd structure
- What does it mean for an action to travel through an entire middleware chain in redux?
- Redux: display single record but json is an array