Persistence

    Client-side data persistence is often crucial to a great mobile experience: remembering a user's preferences and credentials, and showing data immediately when the app starts, instead of showing a spinner while fetching data remotely.

    Generally, there are two ways to persist data on the client:

    • The built-in AsyncStorage API, or libraries wrapping it
    • A native database with JavaScript bindings

    Common options for client-side persistence

    OptionDescription
    AsyncStorageAsyncStorage is a simple, low-level API for a key-value store. You can easily store and retrieve key-value pairs.
    Redux PersistIf you're using Redux, consider using Redux Persist, a library for automatically persisting the state of your Redux store to AsyncStorage on store changes, and rehydrating the store with this saved state when the app launches.
    RealmThe Realm library uses a custom database, written from scratch in C to be compatible on both iOS and Android. We already mentioned Realm under Data Management, but if you're using Realm for managing your data, you get persistence for free!

    Up next

    Let's look at an example using AsyncStorage.

    Want to learn React Native in-depth?

    If you like React Native Express, you'll love my new book, Fullstack React Native: The complete guide to React Native! Throughout the book, we'll build 7 full apps, covering complex topics like navigation, gestures, and native modules. We don't assume any knowledge of React or newer JavaScript language features, so you can dive right in regardless of your experience level. The book comes in PDF, EPUB and MOBI formats.