Search code examples
reactjssessionreduxstore

React: Possibility to store redux store and states into local file?


would it make sense to store the redux store with its states for an application into some local file, e.g like in a .pickle file (in Python), or just save it as some .json file locally to persist the state of an app?

E.g if there is no network connection to persist something to a local database, would it be possible to persist the session in some local storage, or Browser Webstorage or some IndexedDB? And upon the opening of the next session, reload that state again into the store and continue from the session visit?


Solution

  • Sure, you can use redux-persist, this use AsyncStorage to store the information in your reducers.

    https://github.com/rt2zz/redux-persist

    It is able to use in ReactJS and React Native. It is very easy to use, you only need to add some components in your MainApp component, after that, all your Store is saved in the device or navigator.

    You can customize the behaviour to store some information and to store objects.