Complete Guide to Creating a React Native Firebase App

Author

Reads 400

A hand holds a smartphone displaying a modern app interface, with a laptop keyboard in the background.
Credit: pexels.com, A hand holds a smartphone displaying a modern app interface, with a laptop keyboard in the background.

Creating a React Native Firebase app is a straightforward process that involves setting up a Firebase project, installing the Firebase SDK, and integrating it with your React Native app.

First, you need to create a Firebase project in the Firebase console. This will give you a unique project ID that you'll use to configure your app.

You can install the Firebase SDK using npm or yarn by running the command `npm install @react-native-firebase/app` or `yarn add @react-native-firebase/app`.

This will allow you to access Firebase features such as authentication, storage, and real-time database in your React Native app.

On a similar theme: Firebase Next Js

Getting Started

To get started with building a React Native Firebase app, you'll need to choose a target mobile OS, either iOS or Android, or both.

You can set up a React Native development environment for the first time by referring to the React Native Official Documentation.

Setup

To set up a React Native Firebase app, you need to create a project in the Firebase console. Write your project name and click on the continue button to create it, which will integrate with your React Native application.

For more insights, see: Firebase Firestore Nextjs

Credit: youtube.com, React Native Expo Firebase Tutorial: Your First App (2025)

Create an src directory inside the root folder of your project and within it, create three folders: screens, components, and images. This is where you'll organize your app's code.

To add Firebase to your React Native project, run a command at the root of the project, which will initiate the setup process.

Here's an interesting read: Create React App vs Next Js

Create Project

To create a project, you'll need to write your project name and click on the continue button. This will create a project that you can integrate with your React Native application.

The project name is a crucial step, as it will be used to identify your project in the Firebase console. Make sure to choose a name that is easy to remember and relevant to your application.

After creating your project, you'll be taken to the Firebase console, where you can set up your project and configure its settings. You can find more information on setting up your project in the Firebase console by following the instructions provided.

Credit: youtube.com, Siteworks - 01 - Setup a New Project and Create a Design

To get started, you'll need to create a project in the Firebase console. Here's a step-by-step guide:

* Create a project in the Firebase console by writing your project name and clicking on the continue button.

Here's a summary of the steps:

Remember to choose a project name that is easy to remember and relevant to your application. Once you've created your project, you can proceed with setting up your Firebase project.

Auto Registration (iOS)

Auto registration is enabled by default on iOS devices, allowing React Native Firebase Messaging to automatically register the device with APNs to receive remote messages.

You can manually control registration by disabling auto-registration via the firebase.json file.

Once auto-registration is disabled, you must manually call registerDeviceForRemoteMessages in your JavaScript code as early as possible in your application startup.

Default Settings

Setting up your system requires some basic decisions, and one of the first steps is to select default settings.

Credit: youtube.com, Initial Setup and Default Settings

Clicking on continue and saving the default settings is a straightforward process that gets you moving forward.

You'll want to make sure you're on the right track, so double-check that you've saved the default settings correctly.

By selecting default settings, you're essentially opting for the most common or recommended configuration.

This will likely save you time in the long run, as you won't have to worry about tweaking every little detail.

Now that you've selected your default settings, you're ready to move on to the next step.

Enable Email & Password Auth

To enable email and password authentication in Firebase, head on over to your Firebase Project → Authentication → Sign-in Method. Click on Email/Password and set to enabled and save.

Your dashboard should look like this: Email/Password is enabled.

This step is crucial for allowing users to use an email and password combo to log in. Without it, your app won't be able to authenticate users.

Here's a quick checklist to confirm you've enabled Email & Password authentication:

  • Go to Firebase Project → Authentication → Sign-in Method
  • Click on Email/Password and set it to enabled
  • Save your changes

Database

Credit: youtube.com, React native firebase setup | firebase realtime database | firestore

Offline persistence is not supported on other platforms. This means you can't use certain features like keepSynced for offline persistence if you're not on a supported platform.

Unsupported methods include keepSynced, which is specifically for offline persistence. It's good to know what features won't work for you, so you can plan accordingly.

Here are some unsupported methods:

  • keepSynced - for offline persistence

Firestore Data Read/Write

Firestore Data Read/Write is a crucial aspect of building a robust and scalable app. You can write data to Firestore using a simple file that adds a new entity to a collection named "entities".

To simplify data writing, you can create a collection and add items to it. In the article, we see an example of adding a new entity to the "entities" collection.

To query Firestore data, you need to create an index. If you try to query the entities table by authorID and sort the data by createdAt in descending order, you'll get a warning about "The query requires an index". This is because Firestore needs an index to perform this type of query.

Recommended read: React-query Devtools

Credit: youtube.com, Firestore tutorial web read write data firebase get stated beginers database

Creating an index is easy - just click on the URL provided in the warning and click the button. After creating the index, everything works as expected.

Here are some methods for reading and writing Firestore data:

  • loadBundle
  • clearPersistence - for offline persistence
  • disableNetwork - for offline persistence
  • enableNetwork - for offline persistence
  • namedQuery
  • onSnapshot (for both CollectionReference & DocumentReference)
  • GetOptions.source

You can use the onSnapshot method to observe changes in the Firestore collection and have those reflected on the screen in real-time. This is particularly useful in real-time apps, such as a React Native Chat.

You might enjoy: Time Study App

Async Storage

Async Storage is crucial for certain services in React Native Firebase, particularly Auth and Analytics.

Some services require a custom Async Storage implementation to enable persistence, but React Native Firebase provides an API to set this implementation.

You should use the Async Storage implementation that's appropriate for your target platform, not just any example like @react-native-async-storage/async-storage.

If you don't provide an Async Storage implementation, React Native Firebase will use an in-memory implementation, which means data will reset every time your app is restarted.

This can be a problem for Firebase Auth, where users will have to sign in again after each restart, and for Firebase Analytics, where the app will generate a new instance ID and appear as a new installation.

Json

Credit: youtube.com, Build a JSON database in 5 mins with JavaScript

Json is a crucial part of Firebase configuration.

You can configure Firebase's messaging system by editing the firebase.json file, which provides more control over how FCM is handled internally within your application.

This file is essential for customizing your Firebase setup, and it's usually where you'll find the messaging configuration options.

To work with Firebase's messaging system, you need to understand how to edit the firebase.json file, which is a key part of the configuration process.

By configuring your messaging system correctly, you can ensure seamless communication between your app and Firebase.

Features

React Native Firebase app offers a wide range of features that make it an attractive choice for developers.

Firebase provides a Cloud Database Store where you can store and manage your app's data. This feature is especially useful for apps that require real-time data synchronization.

Some of the key features of Firebase include Cloud Database Store, Authentication, Hosting, Storage, and Machine Learning Kit. These features can be summarized in a list:

  • Cloud Database Store
  • Authentication
  • Hosting
  • Storage
  • Machine Learning Kit

These features can help you build a robust and scalable app, and with Firebase's ease of use, you can focus on developing your app's core features without worrying about the underlying infrastructure.

Message Handlers

Credit: youtube.com, Ignition Perspective Message Handler Example - Part 1

Message handlers are a crucial part of Firebase Cloud Messaging (FCM) integration, and they determine how your app responds to incoming messages based on the device state and message contents.

The device state and message contents determine which handler will be called. Here's a breakdown of the possible scenarios:

In cases where the message is data-only and the device is in the background or quit, both Android and iOS will ignore it, unless you set the priority to high (Android) and content-available to true (iOS) properties on the payload.

To handle messages in the background or quit state, you need to setup a background callback handler via the setBackgroundMessageHandler method. This handler must return a promise once your logic has completed to free up device resources, and it must not attempt to update any UI.

Topics

Topics are a great way to simplify FCM server integration, allowing you to send messages to devices subscribed to a named PubSub channel without keeping a store of device tokens.

Credit: youtube.com, Features overview - Topics

You can subscribe a device to a topic by calling the subscribeToTopic method with the topic name, which should not include a forward slash. This is a straightforward process that helps you manage multiple subscriptions efficiently.

One thing to keep in mind is that messages sent to topics should not contain sensitive or private information. This is because topics are meant for public messaging, not personal communication.

Topic messaging supports unlimited subscriptions for each topic, making it a flexible option for your app's needs. This means you can have as many subscribers as you want without worrying about reaching a limit.

However, there are some limits to be aware of. For example, one app instance can be subscribed to no more than 2000 topics, so be mindful of your subscription numbers.

If you're sending a lot of subscription requests in a short period of time, FCM servers will respond with a 429 RESOURCE_EXHAUSTED error. In this case, it's best to retry with exponential backoff.

Here are some key points to remember about topics:

  • Messages sent to topics should not contain sensitive or private information.
  • Topic messaging supports unlimited subscriptions for each topic.
  • One app instance can be subscribed to no more than 2000 topics.
  • The frequency of new subscriptions is rate-limited per project.
  • A server integration can send a single message to multiple topics at once, but this is limited to 5 topics.

Integrations

Credit: youtube.com, How to Create an Expo App with React-Native Firebase

Integrations are a crucial part of building a robust React Native Firebase app. Integrating Firebase into your React Native app provides better protection for your application and users.

React Native allows you to create applications for both Android and iOS platforms, including iOS. You just need to follow some specific steps to do so.

To integrate Firebase into your app, you'll need to set up the prerequisites first. Google Firebase console provides credentials and authentication files for iOS applications as well.

React Native will create the iOS application for you once you have the prerequisites set up.

Analytics

Analytics is a crucial part of any React Native Firebase app, allowing you to track user behavior and make data-driven decisions.

The other platform implementation of Analytics doesn't capture automatic metrics like screen view, so you'll need to call logEvent and other logging based methods to send your events to Firebase.

Output

Output is where the magic happens, and it's all about taking the insights from your analytics and turning them into actionable decisions.

Credit: youtube.com, Data Analytics Terminal : output rendering

Data visualization is a key part of the output process, helping you to quickly understand complex information and make informed choices.

The article section on "Insights" highlights the importance of using data visualization to identify trends and patterns in your data, which can inform your output decisions.

A well-designed dashboard can help you to easily spot areas for improvement and make data-driven decisions, giving you a competitive edge in your industry.

According to the section on "Metrics", the right metrics can help you to measure the effectiveness of your output decisions and make adjustments as needed.

Some common metrics used in analytics include return on investment (ROI) and customer satisfaction (CSAT), which can provide valuable insights into the success of your output.

By regularly reviewing and refining your output, you can ensure that it's aligned with your business goals and objectives, driving long-term success.

Here's an interesting read: Azure App Insight

Status

React Native Firebase supports multiple platforms, including Android and iOS, using the native Firebase SDK for each platform. Android requires a minimum version of 5.0 (Lollipop) without Firebase Auth, but 6.0 (Marshmallow) with Firebase Auth.

Credit: youtube.com, series 8 (POINT OF SALE) analytics data where user see business status

The minimum JDK (Java Development Kit) version required for Android compilation is 17. This is important to note when setting up your development environment.

Below is a table outlining which Firebase modules are supported on each platform in React Native Firebase:

Analytics is supported on all platforms, including Android, iOS, and Other, which includes Web, macOS, Windows, and any other RN based environment.

Analytics

Analytics can be a bit tricky to set up, but don't worry, I've got you covered.

In some platforms, automatic metrics like screen views aren't captured by default, so you need to call logEvent and other logging methods to send your events to Firebase.

You'll need to manually track events to get the data you need, which can take some extra effort but is worth it in the long run.

UI

Implementing the UI in a react native firebase app involves creating the screens that users will interact with. The HomeScreen is a key part of this, and it's implemented in the src/HomeScreen/HomeScreen.js file.

Credit: youtube.com, React Native Firebase Authentication with Expo Router

You can switch between the two screens by tapping the links buttons in the footer. This navigation is a crucial part of the app's user experience.

To create our screens, we need to set up four different screens: Loading, SignUp, Login, and Main. The Loading screen displays until we determine the auth state of a user, while the SignUp and Login screens allow users to create an account and log in, respectively. The Main screen is only shown to authenticated users.

Here's an overview of our screens structure:

  • Loading screen
  • SignUp screen
  • Login screen
  • Main screen

We'll need to add the react-navigation library to navigate between these different screens.

Permissions

Permissions are a crucial aspect of building a React Native Firebase app. iOS requires explicit permission from the user to display messages containing notification payloads.

To request this permission, you can use the requestPermission method provided by the module, which triggers a native permission dialog. This method is essential for handling notifications within your application.

The permissions API for iOS offers fine-grained control over permissions and their handling within your app. To learn more, view the advanced iOS Permissions documentation.

Notifications

Credit: youtube.com, Step-by-Step Guide: Implementing Push Notifications in React Native with Firebase (Android)

Notifications are a crucial part of any mobile app, and in a React Native Firebase app, they're handled through Firebase Cloud Messaging (FCM). To display notifications, your app uses a default Notification Channel ID, which is "Miscellaneous" by default, but you can change it to a custom channel ID by updating the messaging_android_notification_channel_id property in your firebase.json file.

You can also customize the notification behavior by enabling or disabling notification delegation, which is not compatible with react-native-firebase by default. To enable it, you'll need to alter the firebase.json setting messaging_android_notification_delegation_enabled to true.

If your app is running on Android Q+ with current Google Play services, you'll need to use the AndroidManifest.xml method to disable notification delegation, or your messaging listeners won't be called.

Foreground State Messages

In the foreground state, your app is open and in view. You can listen to messages using the onMessage method, which has access to React context and can interact with your application.

Credit: youtube.com, Receive Firebase Data Messages while App in the foreground

The remoteMessage property contains all the information about the message sent to the device from FCM, including any custom data via the data property. To learn more, view the RemoteMessage API reference.

If the RemoteMessage payload contains a notification property when sent to the onMessage handler, the device will not show any notification to the user. Instead, you could trigger a local notification or update the in-app UI to signal a new notification.

Note that if you use @notifee/react-native, since v7.0.0, onNotificationOpenedApp and getInitialNotification will no longer trigger as notifee will handle the event.

To listen to messages in the foreground, call the onMessage method inside of your application code. For example, the React Native Alert API could be used to display a new Alert each time a message is delivered.

Here are the possible scenarios for foreground state messages:

This allows you to update the state or UI in response to incoming messages.

Notification Channel ID

Mobile phone on wooden table showing installation screen for WHO Info app from World Health Organization.
Credit: pexels.com, Mobile phone on wooden table showing installation screen for WHO Info app from World Health Organization.

On Android, any message that displays a notification uses a default Notification Channel created by FCM called "Miscellaneous". This channel contains basic notification settings that may not be suitable for your application.

The default channel may not have the desired notification settings, so it's recommended to update the messaging_android_notification_channel_id property. This allows you to specify a custom channel for your notifications.

Creating and managing channels is outside the scope of the React Native Firebase library, but external libraries like Notifee can provide this functionality.

Frequently Asked Questions

Is React Native Firebase free?

Yes, React Native Firebase is free to use, with Firebase Cloud Messaging (FCM) being a cost-free service for server-device and device-device communication. This means you can start building without worrying about additional messaging costs.

Does Firebase work well with React?

Yes, Firebase and React work well together, as they complement each other's strengths to create a seamless user experience. Combining React's frontend expertise with Firebase's backend capabilities is a match made in tech heaven.

Thomas Goodwin

Lead Writer

Thomas Goodwin is a seasoned writer with a passion for exploring the intersection of technology and business. With a keen eye for detail and a knack for simplifying complex concepts, he has established himself as a trusted voice in the tech industry. Thomas's writing portfolio spans a range of topics, including Azure Virtual Desktop and Cloud Computing Costs.

Love What You Read? Stay Updated!

Join our community for insights, tips, and more.