ThinkGeek
ThinkGeek

Reputation: 5117

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?

Upvotes: 1

Views: 1912

Answers (2)

Uri Klar
Uri Klar

Reputation: 3988

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.

Upvotes: 1

Mario F
Mario F

Reputation: 47279

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.

Upvotes: 1

Related Questions