Couchbase Lite is a NoSQL database designed for mobile and embedded devices, allowing seamless data management even in offline environments. Today, I’m excited to introduce the new React Native – Native Module for Couchbase Lite, now available in public beta on NPM.

Why React Native with Expo?

Building mobile apps with vanilla React Native can be quite challenging due to the complexities around managing routing, modules, and app infrastructure. This is where frameworks like Expo step in to make development more approachable. Expo has become the most popular framework for React Native apps, and the React Native team now recommends using it for new projects, especially for its rich SDK and ease of use.

Our Native Module is designed to work seamlessly with both Expo and React Native apps. For Expo users, running the app in dev-client mode will give access to native modules, making it easier to integrate with Couchbase Lite. Here’s a detailed installation guide for getting started.

Repository & open source project

You can access the React Native – Native Module for Couchbase Lite repository. Being an open-source project, all the project boards and issues are tracked through GitHub. We encourage developers to check out the project, report issues, and contribute.

A key example is the expo-cbl-travel project, which showcases Couchbase Lite’s features like replication, SQL++ querying, and Full-Text Search (FTS). This project is designed to work with Couchbase Capella App Services. We’ve made it easy for developers by providing a step-by-step guide to set up Couchbase Capella’s Free-Tier for use with the mobile app. You can find the expo-cbl-travel repository here. You can watch the walkthrough video here:

A Simple Example with Couchbase Lite

Here’s a brief example of how easy it is to interact with Couchbase Lite using the React Native Module. This demonstrates opening a database, retrieving a document, modifying it, and saving the changes:

In this example:

    • A new database called my-database is created (or opened if it already exists)
    • We create a Mutable document with the ID doc-1
    • We modify the document by adding a firstName field and setting the value
    • We then save the document
    • Next we get the document back from the database
    • If the document exists, we modify its name and age properties
    • The modified document is then saved back to the database

This simple code snippet demonstrates the power of Couchbase Lite for handling local data efficiently. More complex scenarios, such as querying data, handling replication, or using Full-Text Search (FTS), can be explored through our documentation.  

Current issues and future enhancements

We are actively working to address known issues:

    • Change listeners: We are currently fixing issues which will make change listeners functional in the next update.
    • Date Query Parameters on Android: There are minor issues with parsing dates on Android, which we plan to resolve soon.

The public beta version (0.2.0) is currently based on Couchbase Lite 3.1.x, and we’ll be upgrading to Couchbase Lite 3.2 in the near future.

How you can help

We invite developers to try the beta, build sample apps, and provide feedback. Your input is invaluable in helping us identify and fix issues quickly. You can submit issues or suggestions on our GitHub issues page.

Author

Posted by Aaron LaBeau - Principal Software Engineer

Aaron LaBeau is a Principal Software Engineer on the Developer Experience and Ecosystem team. He has over 29 years with substantial development experience in Objective-C, Swift, Kotlin, Java, C#, Javascript, and Typescript. You can find his GitHub profile at https://www.github.com/biozal/.

Leave a reply