What is the lifetime of state in React-Redux?

Viewed 561

I cannot find documentation that says how long a state will hold its values. I read that if a page refreshes, then the state will be lost, but what about when redirecting to another component/page? Will the state be lost if I redirect from one component to another?

Or does the state last until the user physically refreshes the page?

1 Answers
  • your state is lost when the page is refreshed (i.e. when the component is unmounted)
  • when you navigate to another component/page, your state is NOT lost. With react router navigations and react re-renders, the state is not lost.
  • If you want to retain state after page refresh then you need to store your state in localStorage & retain the state upon component mount.
Related