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

55 lines
2.0 KiB
Markdown
Raw Normal View History

2017-03-02 12:50:09 +00:00
# Firebase Setup
The RNFirebase library is intended on making it easy to work with [Firebase](https://firebase.google.com/) 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](https://firebase.google.com/console)
![Create a new project](http://d.pr/i/17cJ2.png)
Each platform uses a different setup method after creating the project.
## iOS
2017-04-06 13:41:10 +00:00
See the [ios setup guide](./installation.ios.md).
2017-03-02 12:50:09 +00:00
## Android
2017-04-06 13:41:10 +00:00
See the [android setup guide](./installation.android.md).
2017-03-02 12:50:09 +00:00
## Usage
After creating a Firebase project and installing the library, we can use it in our project by importing the library in our JavaScript:
```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:
```javascript
2017-04-06 12:01:21 +00:00
const firebase = RNFirebase.initializeApp({
// config options
});
2017-03-02 12:50:09 +00:00
```
2017-04-06 12:15:44 +00:00
### Configuration Options
2017-03-02 12:50:09 +00:00
| 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:
```javascript
2017-04-06 12:15:44 +00:00
import RNFirebase from 'react-native-firebase';
2017-03-02 12:50:09 +00:00
const configurationOptions = {
debug: true
};
2017-04-06 12:15:44 +00:00
const firebase = RNFirebase.initializeApp(configurationOptions);
export default firebase;
2017-03-02 12:50:09 +00:00
```