简体   繁体   中英

Delete redux state on navigating to a different route in react-redux application?

I am writing a react-redux application, that has some 4 routes. I am using react-router to navigate to different routes. My question here is, is it recommended to delete redux state on navigating to a different route?

In general I would not say it is needed to delete existing state when transitioning to another route in the app. If you come back to that part, you can display data faster. You might need to consider if there is a need to refresh that when you come back to it.

As other's here said, there is no reason to delete state from redux, even if you're not using it in the current route.

You said that you're loading your state on componentDidMount . Do you want to reload server data every time a route is switched? Because if not, you can add a condition to your componentDidMount to only re-load the data from the server if it hasn't been loaded yet.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM