Search code examples
reactjsreduxreact-routerstore

Redux losing state on page reload and in my app i can't use localStorage


Redux losing state on page reload and in my app i can't use localStorage. What can be the best option: I cant use localStorage for policy reason, so persisting not helping me at all.

  1. Can I set up react-router somehow to save data in redux store over all app
  2. Redux router?
  3. ...

Solution

  • You need to store the redux state somewhere, otherwise it will be lost on reload. Options for saving the state include localStorage, sessionStorage, cookies, file system, pouch db and many others.

    Handling this on you own is possible but probably unnecessary. There are libraries like https://www.npmjs.com/package/redux-persist or https://www.npmjs.com/package/redux-storage that handle it for you. Since local storage is not possible in your case you should use the first option offering various different storage engines.