Data Management

    Most apps manage data as JavaScript objects. For example, data like user info, images, documents, contacts, etc, might be fetched from disk or a remote API, and then stored in-memory as JavaScript objects. It's up to us to figure out how we want manage these JavaScript objects, and propagate them into our React components. If the user can edit this data, we also need to figure out how to sync any changes back to where the data was stored originally.

    There are several ways to manage data throughout an app, and the best choice depends on the complexity of an app. When in doubt, start simple, and as your application grows in complexity, use something more advanced.

    Common options for managing data

    Here are a few options worth considering for managing your data.

    OptionDescription
    useReducerReact provides a hook for storing data. This is a great place to start.
    ReduxRedux provides a store object which maintains the application state, and can notify our React components when state changes. Redux was designed with React in mind, and has official React bindings: React Redux. There are additional tools around Redux to provide: control over asynchronous events, data persistence (for offline usage, etc), and more powerful debugging.
    MobXState management through "functional reactive programming". MobX was designed for use with React, and provides utilities like observables to manage state changes.
    RealmThe Realm library uses a custom database, written from scratch in C to be compatible on both iOS and Android. Realm is suitable for apps with a tremendous amount of data (10,000+ records). If an app can't fit all its data in RAM, using a database makes it easy to page records in and out, or search without loading all data into memory.

    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.