Search code examples
javascriptreactjsreact-nativeoffline-mode

Offline mode in react native


I have an application which uploads some user information to a server using internet. Is there any methods to store user information in the local storage when there is no internet connectivity and uploads the same when connected to a network (Like offline Mode) ?


Solution

  • Try Redux with Redux-Persist.

    You can use Async storage to maintain proper structure and Async rendering too (other benefits of redux).

    You can do something like

    const persistConfig = {
          key: 'root',
          storage,
          whitelist: ['aaaa', 'vvvv'],
        };
    

    where storage can be of different types:

    • localStorage
    • SessionStorage
    • Async Storage

    as mentioned in redux persist docs

    Also, you can blacklist (except) or whitelist (only) certain reducers

    Persisting makes sure that data exist even after the app is reopened. and every x time interval or action you can fire the queue and clean it up.