Firebase Tutorial episode #1
Kickstart your React Native app with Firebase — Cloud Firestore (Tutorial #1)
In this series we will create an iOS and Android application — called Fakestagram — with React Native, using some of Firebase services. This is not an “intro to React Native” tutorial so we won’t cover basic things, but only Firebase specific topics, so you will need some React Native knowledge to keep up with the pace.
Today, in Ep. 1, we will look at Firebase’s exciting new feature, Cloud Firestore. If you want to read the intro article check out Episode #0, soon you can check the next step in Episode #2.
In the previous
A NoSQL (originally referring to “
According to official documentation, Cloud Firestore is a cloud-hosted, NoSQL database that your iOS, Android, and web apps can access directly via native SDKs. Cloud Firestore is also available in native Node.js, Java, Python, and Go SDKs, in addition to REST and RPC APIs.
First, let’s create our database model at the Firebase console and populate it with some dummy data. To do this, choose database from the left navigation, then Cloud Firestore and activate test mode. This will create the DB engine. (In the next article, where we create authentication feature, we will set the DB to only authenticated users can write.)
Test mode == Anybody can read/write any documents in the DB (!)
First, we only need 1 collection for the posts. A post will have a unique ID, a
Connecting the DB to the app
Now, that the database is created, it’s time to use it.
So on iOS add pod ‘Firebase/Firestore’to your Podfile, do a pod update and from now, you can use Cloud Firestore features on iOS.
On Android add compile “com.google.firebase:firebase-firestore:11.6.0” to app/build.gradle. Add import io.invertase.firebase.firestore.RNFirebaseFirestorePackage; and new RNFirebaseFirestorePackage()to MainApplication.java and now it works on Android.
We only work on App.js now, creating a FlatList and a ListItem — called Post — to render the data from our DB.
You should clearly see that’s really easy to add a new document to a collection by calling .add() method on our ref. Just put the object to the parameter of the function.
This is all you need to start using Cloud
In the next
Check out the full code here:
Register to our next workshop!
Subscribe to our newsletter, and we will provide you more practical tips regarding mobile development:
Bene studio HQ
Andrássy út 66., 1062 Budapest
+36 70 682 9425