0
0
React Nativemobile~5 mins

Firebase setup (@react-native-firebase) in React Native

Choose your learning style9 modes available
Introduction

Firebase helps your app store data and authenticate users easily. Setting it up connects your app to Firebase services.

You want to save user data like profiles or messages.
You need to let users sign in with email or social accounts.
You want to add push notifications to your app.
You want to track app usage and errors automatically.
Syntax
React Native
npm install --save @react-native-firebase/app

// For example, to add authentication:
npm install --save @react-native-firebase/auth

// Then link native code (if needed):
npx pod-install
Use npm or yarn to install Firebase packages.
Run npx pod-install after installing packages to update iOS dependencies.
Examples
Installs the core Firebase package needed for all Firebase features.
React Native
npm install --save @react-native-firebase/app
Installs Firestore to use Firebase's cloud database.
React Native
npm install --save @react-native-firebase/firestore
Updates iOS native dependencies after installing Firebase packages.
React Native
npx pod-install
Sample App

This simple app shows the Firebase app name to confirm Firebase is set up correctly.

React Native
import React from 'react';
import {Text, View} from 'react-native';
import firebase from '@react-native-firebase/app';

export default function App() {
  const appName = firebase.app().name;
  return (
    <View style={{flex:1, justifyContent:'center', alignItems:'center'}}>
      <Text>Firebase App Name: {appName}</Text>
    </View>
  );
}
OutputSuccess
Important Notes

Make sure to add your google-services.json (Android) and GoogleService-Info.plist (iOS) files to your project.

Always run npx pod-install after adding new Firebase packages for iOS.

Check Firebase console to create your project and download config files.

Summary

Install @react-native-firebase/app to start using Firebase.

Add specific Firebase packages like @react-native-firebase/auth as needed.

Include config files and run pod install for iOS to complete setup.