Reputation: 37
I am using history.push() to redirect to a page and passing some props like below:
const ViewDetailCellRenderer = (props: any) => {
let history = useHistory();
const scenario = props.data;
const onButtonClick = (event: React.KeyboardEvent | React.MouseEvent) => {
history.push({
pathname: `/scenario-details/${scenario.ID}/kpi`,
state: {
scenario: scenario,
},
});
};
return (
<Button color="secondary" label="View →" onClick={onButtonClick} />
);
};
In the new page I am able to access the data using location.state. The problem I am facing is that on page refresh the location.state is undefined. I am able to access the scenario id using props.match.params. Is there a better way to do this? My last option would be to use local storage but not sure if thats the best solution.
Upvotes: 0
Views: 763