Hi there, welcome to this tutorial! ๐
Today, I will be showing you how to perform super fast CRUD operations with Firebase (version 9) by building a shopping list web application.
The prerequisite for this tutorial is a basic knowledge of React and React hooks.
CRUD means Create, Read, Update and Delete operations.
Also, if this is your first time using Firebase, you don't need to be afraid. We will be going through it together in this tutorial with enough code samples.
Before we begin
These are the required steps you are to take:
๐ Set up a react-app project UI similar to this.
๐ Make sure you sign in to your Gmail account
๐ Head over to Firebase console
๐ Click on "Go to Console" at the top navigation bar
๐ Create a Firebase project
๐ You can disable Firebase analytics, we don't need it and check the boxes to create the project
๐ Also, create a Firebase web app, by clicking on the highlighted icon (Web).
๐ Pick a name for your app, if you are interested in Firebase hosting, check the box for hosting.
๐ Copy the Firebase SDK configuration in the image below, to a "firebase.js" file created in the root of your create-react-app project.
๐ Also, add the following below the copied code in "firebase.js
//At the top
import { getFirestore } from 'firebase/firestore';
//Below the import code
const db = getFirestore(app);
export default db
๐ Run the command below to install firebase tools.
npm i -g firebase-tools
๐ Run the command below in your react project folder, in order to install firebase.
npm i firebase
๐ Click continue to console
Once you're done completed the steps! We are good to go.
CRUD operations with Firebase
Let's quickly go over some of the imported codes above.
When using Firebase as a backend service, the database is called Firestore, and the function getFirestore() is used to access the database.
getFirestore() enables you to create any database of your choice.
Let's go back to the Firebase console
๐ Click on Build and select Firestore Database to create your database.
๐ Create a database in test mode
๐ Create a Collection "shopping lists" and a string value for the document, because our shopping items are string variables.
๐ Finally our database has been set up, now let's interact with it from our React app
How to Get the List of Shopping Items
How to Add Items to our Shopping List when the Save Button is clicked
How to Delete Items from the list
How to Update Items
Check out the Source Code
REFERENCE:
๐ Firebase v9 Documentation
๐ Firebase v9 CRUD Playlist on Youtube
Hope you enjoyed this tutorial?
Feel free to follow for more interesting and educative posts and also Connect with me on
๐ Linkedin
๐ Twitter
Top comments (1)
How to add pagination? Include pagination in this as well. In the documentation it is not clear.