Build a Simple Contact Form With React Hooks, Firebase, Nodemailer, and Axios
A step-by-step tutorial

You could imagine my surprise when I went on the web to look for a straightforward contact form implementation using React and Firebase and couldn’t find one. I wanted it to send an email to my inbox when someone tried to contact me on my website. Oh, and did I mention I wanted it to store the email data in my Firebase database? Can I also get something with hooks? Maybe a cherry on top. Please and thank you.
Why didn’t this exist?
Oh well. When in Rome, do as the Romans do — make documentation. That’s the saying, right?
A lot of the time, you want the quick and easy answer to focus on the good stuff. Here, to save you from ripping your hair out strand by strand, I’ll give you a super-straightforward tutorial.
What Do I Get With This?
A contact form for your site that sends you an email notification when someone hits that “Submit” button. You get an email in your inbox saying something like, “Hey hey, so-and-so just sent you a message saying this and that. Hurry up and reply.” You’ll get to see their name, email, and message in your inbox.
Do you want a tutorial with less technical jargon and more vanilla English? Done and done.

Technologies and Packages Used
- React
- React Hooks
- Firebase
- Nodemailer
- Axios
- Cors
- Gmail
Step 1: Open Your React App Terminal and Install the Dependencies You Will Use for This Project
$ npm install firebase axios node-sass
$ npm install -g firebase-toolsYou should now have Firebase listed in your package.json file.
Step 2: Add Your Project in Firebase
1. Go to the Firebase website. Click “Create a project” and complete the required steps.

2. Click the web icon.

3. Click the “Add Firebase to your web app” option to get your config variables and copy your config code. Click “Continue to console.” You will need these values in your .env file later in this tutorial.

Step 3: Set Up Your Database With Cloud Firestore
Note: You can skip this step if you don’t want your email data added in the DB. The benefit of using this is being able to see a record of contact submissions.
1. Click “Create database.”

2. Start in test mode for the time being and change later if you’d like to.

3. Click “Start collection.” You can call the collection “emails.”

4. Insert your first entry manually (not sure why this is needed, but you can delete your entry later if you like).

Step 4: Initialize Firebase
1. Initialize Firebase using the following command:
$firebase initYou will be prompted for the following:
- Which Firebase CLI features do you want to set up for this folder? Press Space to select features, then Enter to confirm your choices. → Functions: Configure and deploy Cloud Functions.
- What language would you like to use to write Cloud Functions? → JavaScript
- Do you want to use ESLint to catch probable bugs and enforce style? → n
- Do you want to install dependencies with npm now? → y
Step 5: Add Your .env Variables
1. Create an .env file in the root of your project (don’t forget to add this your .gitignore file if it’s not in this already). This is where you will store all of your config values.
REACT_APP_FIREBASE_API_KEY=<yourapikey>
REACT_APP_FIREBASE_AUTH_DOMAIN=<authdomain>
REACT_APP_FIREBASE_DATABASE_URL=<databbase>
REACT_APP_FIREBASE_PROJECT_ID=<projectid>
REACT_APP_FIREBASE_STORAGE_BUCKET=<storage bucket>
REACT_APP_FIREBASE_MESSAGING_SENDER_ID=<messagingsender>Step 6: Add Your Firebase Configurations Into Your Project
1. In your /src folder, add a sub-folder called /firebase and a file called /firebaseConfig.js.

2. In firebaseConfig.js, add the following code:










