react-native-firebase/docs/firebase-setup.md

2.0 KiB

Firebase Setup

The RNFirebase library is intended on making it easy to work with Firebase and provides a small native shim to the Firebase native code.

To add Firebase to your project, make sure to create a project in the Firebase console

Create a new project

Each platform uses a different setup method after creating the project.

iOS

See the ios setup guide.

Android

See the android setup guide.

Usage

After creating a Firebase project and installing the library, we can use it in our project by importing the library in our JavaScript:

import RNFirebase from 'react-native-firebase'

We need to tell the Firebase library we want to configure the project. RNFirebase provides a way to configure both the native and the JavaScript side of the project at the same time with a single command:

const firebase = RNFirebase.initializeApp({
  // config options
});

Configuration Options

option type Default Value Description
debug bool false When set to true, RNFirebase will log messages to the console and fire debug events we can listen to in js
persistence bool false When set to true, database persistence will be enabled.

For instance:

import RNFirebase from 'react-native-firebase';

const configurationOptions = {
  debug: true
};

const firebase = RNFirebase.initializeApp(configurationOptions);

export default firebase;