Metizsoft Solutions

How to Integrate Firebase Real-Time Database in React Native?

React Native Real Time Firebase
React Native Real Time Firebase

Firebase has proved to be a great boon to mobile and web app development. The backend support it provides is very handy in app development. It really enhances the overall app’s functionality.

This document will help you show the integration with Firebase and demonstrate how you can insert and retrieve data using Firebase.

But before going further let’s see some of the positive aspects of Firebase for an external database.

Table of Contents

Why use Firebase:

  • Faster compared to REST APIs
  • Real-time callback
  • Easy to integration
  • Offline access to cached data
  • Manage by Google so better security

So you get an idea of why Firebase is ruling these days and why you should choose this ‘support system’. Now we turn to the installation process.

Installation:

Create a project using below command $ react-nativeinit “ProjectName” Now install Firebase into Your project $ npm i -S firebase So now firebase is installed into your project.

I believe you have already created an android project in the Firebase console. If not then please add Project in Firebase using this Link. If you are an absolute beginner then you can check out this Link to understand how to create a project in the Firebase console.

Implementation:

After creating a project you need to add firebase config into your app. There will be three options in the console Android, iOS, and Web app, You have to select web app.

Implementation

On click of the third option, the below screen will see below the screen and you need to copy this config and paste it into your component Will Mount () method.

Add-Firebase-to-Web-App

Now select the database from the slider under the develop section.

select database

After selecting a database, you must check that you have selected a real-time database, not a cloud firebase. And in the rules tab, you must have to select read and write as true so that it allows you to read and write database without any authentication.

Real Time Database

Now you are ready to use firebase inside your app and play with it.

Usage:

  • INSERT

In this demo, I am storing Users in a list so in Firebase I have a list of Users and can get all the users.

The below screenshot explains inserting user objects into firebase. You can change the list object name from ‘users’ to whatever you want to add and customize the object according to your record.

React Database
  • RECEIVE

This block of code returns the list of objects if you have inserted any. And you can play like you can check if a user is in a list and create login and signup using these blocks of code.

List of object

Your inserted records will display like below

database rules

We hope that we have covered all the basics regarding Firebase Real-time Database in React Native. For more information, we are here to help you at metizsoft.com.

We develop cross-platform apps using React Native Technology and provide budget-friendly tech solutions to our clients.

Read More:

Top 5 Reasons to choose React Native Framework
React Native Document Scanner (iPhone Only)
Image picker React Native

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

CONTACT US

Telephone

Flag_of_the_United_States

+1 (845) 418-5206 (Toll Free)

(If we don’t pick up, drop inquiry. We will contact you.)

Email

Modern Tech

3000+ projects. Clear vision.

Proven Results

Tech that wins. Lasting impact.

Global Reach

Innovating in 30+ countries.

Certified Excellence

Recognized for proven innovation.