How do I clear location.state in react-router on page reload?

Reactjs

I am currently passing my state on route change like below:

<Link to={{           pathname:`/transactions/${props.transaction.id}`,           state: {transaction: props.transaction}         }}> View Details </Link>

My logic is that if "location.state.transaction" exists, don't fetch new data, else, fetch data.

Now the flaw is when there is a page reload. The application needs to fetch new data if the user reloads the page. I thought "location.state" would get cleared if there is a reload, but apparently the state is saved in sessionStorage.

How do I work around this? I could just fetch new data every time, but it should not fetch data when the 'View Details' Link is clicked.

Answer link : https://codehunter.cc/a/reactjs/how-do-i-clear-location-state-in-react-router-on-page-reload

Posted Mar 22, 2022, 9:11 PM UTC

10
Loading comments…