Close Menu
Soshace Digital Blog

    Subscribe to Updates

    Get The Latest News, Updates, And Amazing Offers

    What's Hot
    Programming

    Best Practices for Writing Clean and Maintainable Code

    Interview

    Interview with Anuar Akhmetov: I Was Apathetic of Programming until I Met My Very Best Mentor

    LinkedIn

    Strategies for Identifying Quality LinkedIn Prospects by Niche

    Important Pages:
    • Home
    • About
    • Services
    • Contact Us
    • Privacy Policy
    • Terms & Conditions
    Facebook X (Twitter) Instagram LinkedIn YouTube
    Today's Picks:
    • Scaling Success: Monitoring Indexation of Programmatic SEO Content
    • Leveraging Influencers: Key Drivers in New Product Launches
    • How Privacy-First Marketing Will Transform the Industry Landscape
    • The Impact of Social Proof on Thought Leadership Marketing
    • Balancing Value-Driven Content and Promotional Messaging Strategies
    • Top Influencer Marketing Platforms to Explore in 2025
    • Emerging Trends in Marketing Automation and AI Tools for 2023
    • Strategies to Mitigate Duplicate Content in Programmatic SEO
    Wednesday, September 10
    Facebook X (Twitter) Instagram LinkedIn YouTube
    Soshace Digital Blog
    • Home
    • About
    • Services
    • Contact Us
    • Privacy Policy
    • Terms & Conditions
    Services
    • SaaS & Tech

      Maximizing Efficiency: How SaaS Lowers IT Infrastructure Costs

      August 27, 2025

      Navigating Tomorrow: Innovations Shaping the Future of SaaS

      August 27, 2025

      Maximizing Impact: Strategies for SaaS & Technology Marketing

      August 27, 2025
    • AI & Automation

      Enhancing Customer Feedback Analysis Through AI Innovations

      August 27, 2025

      Navigating the Impact of AI on SEO and Search Rankings

      August 27, 2025

      5 Automation Hacks Every Home Service Business Needs to Know

      May 3, 2025
    • Finance & Fintech

      Critical Missteps in Finance Marketing: What to Avoid

      August 27, 2025

      Analyzing Future Fintech Marketing Trends: Insights Ahead

      August 27, 2025

      Navigating the Complex Landscape of Finance and Fintech Marketing

      August 27, 2025
    • Legal & Compliance

      Exploring Thought Leadership’s Impact on Legal Marketing

      August 27, 2025

      Maximizing LinkedIn: Strategies for Legal and Compliance Marketing

      August 27, 2025

      Why Transparency Matters in Legal Advertising Practices

      August 27, 2025
    • Medical Marketing

      Enhancing Online Reputation Management in Hospitals: A Guide

      August 27, 2025

      Analyzing Emerging Trends in Health and Medical Marketing

      August 27, 2025

      Exploring Innovative Content Ideas for Wellness Blogs and Clinics

      August 27, 2025
    • E-commerce & Retail

      Strategic Seasonal Campaign Concepts for Online and Retail Markets

      August 27, 2025

      Emerging Trends in E-commerce and Retail Marketing Strategies

      August 27, 2025

      Maximizing Revenue: The Advantages of Affiliate Marketing for E-Commerce

      August 27, 2025
    • Influencer & Community

      Leveraging Influencers: Key Drivers in New Product Launches

      August 27, 2025

      Top Influencer Marketing Platforms to Explore in 2025

      August 27, 2025

      Key Strategies for Successful Influencer Partnership Negotiations

      August 27, 2025
    • Content & Leadership

      The Impact of Social Proof on Thought Leadership Marketing

      August 27, 2025

      Balancing Value-Driven Content and Promotional Messaging Strategies

      August 27, 2025

      Analyzing Storytelling’s Impact on Content Marketing Effectiveness

      August 27, 2025
    • SEO & Analytics

      Scaling Success: Monitoring Indexation of Programmatic SEO Content

      August 27, 2025

      Strategies to Mitigate Duplicate Content in Programmatic SEO

      August 27, 2025

      Effective Data Visualization Techniques for SEO Reporting

      August 27, 2025
    • Marketing Trends

      How Privacy-First Marketing Will Transform the Industry Landscape

      August 27, 2025

      Emerging Trends in Marketing Automation and AI Tools for 2023

      August 27, 2025

      Maximizing ROI: Key Trends in Paid Social Advertising

      August 27, 2025
    Soshace Digital Blog
    Blog / JavaScript / React / React Native / React Native Lessons / Build Real-World React Native App #7: Send Feedback with Formik, Yup, Firebase Cloud Function and Sendgrid
    React Native

    Build Real-World React Native App #7: Send Feedback with Formik, Yup, Firebase Cloud Function and Sendgrid

    Krissanawat KaewsanmuangBy Krissanawat KaewsanmuangDecember 15, 2020No Comments10 Mins Read
    Facebook Twitter Pinterest Telegram LinkedIn Tumblr Email Reddit
    Build Real-World React Native App #7: Send Feedback with Formik, Yup, Firebase Cloud Function and Sendgrid
    Build Real-World React Native App #7: Send Feedback with Formik ,Yup ,Firebase Cloud Function and Sendgrid
    Share
    Facebook Twitter LinkedIn Pinterest Email Copy Link
    Build Real-World React Native App #7: Send Feedback with Formik ,Yup ,Firebase Cloud Function and Sendgrid
    Build Real-World React Native App #7: Send Feedback with Formik, Yup, Firebase Cloud Function, and Sendgrid

    In this chapter, we will create a simple form in the Feedback.js file using Formik and submit form data to the Firebase Realtime Database. Then, we will subsequently forward the message to the sender’s email using Cloud Function and Sendgrid. The form will be for users to send their feedback on the post articles and the app.

    Let’s get started!

    Setup Formik and Yup

    First, we are going to install the required packages Formik and Yup. Formik package enables us to build forms whereas the Yup package is for form validation. We are also going to install another package that is react-native-keyboard-aware-scroll-view which enables us to scroll the view upwards when the keyboard pops up from the bottom. This will provide a better user experience. Now, in order to install these packages, we need to run the command given in the following code snippet in our project terminal:

    yarn add formik yup react-native-keyboard-aware-scroll-view

    Now, we need to open the Feedback.js file and import the necessary packages and their components as shown in the code snippet below:

    import React from 'react'
    import { View, StyleSheet } from 'react-native'
    import { TextInput as Input, Button, HelperText } from 'react-native-paper'
    import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view'
    import { Formik } from 'formik';
    import * as Yup from 'yup'

    Next, we need to create a simple form using Formik. First, we need to set the initial input values as blank. When a user submits the form, we need to call the submitForm function which will also display an error if any using helper text. The function that returns the form configuration is provided in the code snippet below:

    const Feedback = () => {
    return (
           <Formik
               initialValues={{ email: '', name: '', message: '' }}
               onSubmit={(values, { setSubmitting }) => {
                   console.log(values)
                   submitForm(values);
                   setSubmitting(false);
               }}
               validationSchema={FeedbackSchema}
           >
               {({ handleChange, handleBlur, handleSubmit, values, isValid, dirty, errors, touched, isSubmitting }) => (
                   <KeyboardAwareScrollView>
                       <View style={styles.container}>
                           <Input
     
                               placeholder={'Name'}
                               onChangeText={handleChange('name')}
                               onBlur={handleBlur('name')}
                               value={values.name}
                               underlineColor="transparent"
                               mode="outlined"
     
                           />
                           <HelperText
                               type="error"
                               visible={errors.name && touched.name}
                           >  {errors.name}</HelperText>
                           <Input
     
                               placeholder={'Email'}
                               onChangeText={handleChange('email')}
                               onBlur={handleBlur('email')}
                               value={values.email}
                               underlineColor="transparent"
                               mode="outlined"
     
                           />
                           <HelperText
                               type="error"
                               visible={errors.email && touched.email}
                           >  {errors.email}</HelperText>
                           <Input
     
                               placeholder={'Message'}
                               onChangeText={handleChange('message')}
                               onBlur={handleBlur('message')}
                               value={values.message}
                               underlineColor="transparent"
                               mode="outlined"
                               multiline={true}
                               numberOfLines={12}
                           />
                           <HelperText
                               type="error"
                               visible={errors.message && touched.message}
                           >  {errors.message}</HelperText>
                           <View >
                               <Button icon="email" disabled={!isValid} mode="contained" onPress={handleSubmit}>
                                  Submit
                                  </Button>
                           </View>
                       </View>
                   </KeyboardAwareScrollView>
               )}
           </Formik>
       )
    }
     
    export default Feedback

    Next, we need to create the validation rules using Yup as shown in the code snippet below:

    const FeedbackSchema = Yup.object().shape({
       name: Yup.string()
           .min(2, "name is Too Short!")
           .max(50, "name is Too Long!")
           .required("name is Required"),
       // recaptcha: Yup.string().required(),
       email: Yup.string()
           .email("Invalid email")
           .required("Email is Required"),
       message: Yup.string()
           .min(12, "message is Too Short!")
           .max(50, "message is Too Long!")
           .required("message is Required"),
    });

    Hence, we will get the form view as shown in the emulator screenshots below:

    Feedback screen with React Native
    Feedback screen with React Native

    And, when we submit the form with empty fields, we will get the error message as well as shown in the emulator screenshots below:

    Yup validation in React Native
    Yup validation in React Native

    Now that we have the form view, we will move on to set up Firebase in our React Native project.

    Setting up React Native Firebase

    Here, we are going to use the react-native firebase version 6 package in order to access Firebase services. Initially, we only require the core Firebase package and real-time database. So, we need to install them using the command provided below:

    yarn add @react-native-firebase/app @react-native-firebase/database

    Setup on iOS

    In iOS, we start by installing React native Firebase on cacao pod by using the command provided below:

    cd ios ; pod install

    Next, we need to open the project with Xcode and find the Bundle identifier as shown in the screenshot below:

    Read More:  React Native vs. Flutter: Which One Would Suit You Better?
    Xcode setup
    Xcode setup

    Next, we need to go to Firebase Console and create a new app. Then, choose an iOS app and add Bundle identifier as shown in the example screenshots below:

    Add new Firebase app
    Add new Firebase app

    Next, we need to download the GoogleService-info.plist file as shown in the screenshot below:

    Download Google service info
    Download Google service info

    Then, we need to move the plist file to the Xcode project structure as shown in the screenshot below:

    Add Google service info to Xcode
    Add Google service info to Xcode

    Next, we need to open Appdelegate.m file in Xcode and import Firebase then activate [FIRApp configure]; as highlighted in the example screenshot below:

    Xcode appdelegate
    Xcode appdelegate

    Now, if everything works according to the right setup then we will see the following status on Firebase when we re-run the app:

    Finalise setup IOS in Firebase
    Finalise setup IOS in Firebase

    Setup on Android

    For Android, we need to locate the file named MainApplication.java as shown in the screenshot below:

    Mainapplication.java
    Mainapplication.java

    Then, we need to copy the package name back to the Firebase console. The package name that we will get in the MainApllication.java file is shown below:

    package com.kriss;

    After copying, we need to create a new android app in the Firebase console and paste the package name in the config form as shown in the screenshot below:

    Add Firebase to Android app
    Add Firebase to Android app

    After that, we will get the google-service.json file which we need to download as shown in the screenshot below:

    Download Google services
    Download Google services

    After downloading, we need to copy it to the location as shown in the screenshot below:

    Move Google service.json to Android
    Move Google service.json to Android

    Next, we need to open android/build.gradle and add classpath as ‘com.google.gms:google-services:4.2.0’ to dependencies as shown in the code snippet below:

    buildscript {
       ext {
           buildToolsVersion = "28.0.3"
           minSdkVersion = 16
           compileSdkVersion = 28
           targetSdkVersion = 28
       }
       repositories {
           google()
           jcenter()
       }
       dependencies {
           classpath("com.android.tools.build:gradle:3.4.2")
           classpath 'com.google.gms:google-services:4.2.0'
           // NOTE: Do not place your application dependencies here; they belong
           // in the individual module build.gradle files
       }
    }

    Then, we also need to add apply plugin: ‘com.google.gms.google-services’ configuration to the last line of android/app/build.gradle file as shown in the code snippet below:

    task copyDownloadableDepsToLibs(type: Copy) {
       from configurations.compile
       into 'libs'
    }
     
    apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
    apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"
    apply plugin: 'com.google.gms.google-services'

    Hence if we re-run the app, we will get the following logs in our metro bundler:

    Re-run bundle server
    Re-run bundle server

    Now, if everything works fine, we will get the following result in our Firebase:

    Finalize setup Firebase on Android
    Finalize setup Firebase on Android

    Using Database package

    Here, we go back to Feedback.js and import Firebase realtime database package as shown in the code snippet below:

    import database from '@react-native-firebase/database'

    First, we need to create a function named submitForm and call the realtime database as shown in the code snippet below:

    const submitForm = (values) => {
           database()
               .ref("feedback/")
               .push(values)
               .then(res => {
                   alert("thank for giving feedback");
               })
               .catch(err => {
                   console.error(err);
               });
       }

    Now, if we try to submit the form, we will get an alert as shown in the emulator screenshot below:

    Submit data to Firebase
    Submit data to Firebase

    In order to make a navigation link to the Feedback screen, we need to add a menu option to our Settings.js screen file. For this, we need to use the code from the following code snippet:

    import React, { useContext, useState } from 'react';
    import { View, TouchableOpacity } from 'react-native';
    import {
       List, Switch,
    } from 'react-native-paper';
    import React, { useContext, useState } from 'react';
    import { View, TouchableOpacity } from 'react-native';
    import {
       List, Switch,
    } from 'react-native-paper';

    Then, we need to use the TouchableOpacity component to implement clickable menu option as shown in the code snippet below:

    const Setting = ({ navigation }) => {
       return (
       <View style={{ flex: 1 }}>
           <TouchableOpacity
               onPress={() => navigation.navigate('Feedback')}>
               <List.Item
                   title="Send Feedback"
                   left={() => <List.Icon icon="email" />}
               />
           </TouchableOpacity>
       </View >
       );
    }
    export default Setting;

    Here, we have added a navigation configuration to the Feedback screen using the navigate function provided by the navigation option.

    Read More:  Build Real-World React Native App #3: Home Screen With React Native Paper

    Hence, we will get the following result as shown in the emulator screens below:

    Setting screen menu
    Setting screen menu

     

    Sending email with Firebase Cloud Function

    The last thing we need to do is to forward a message to the user’s inbox using the Firebase cloud function.

    For that we need to install the firebase-tools package globally using NPM as shown below:

    npm install -g firebase-tools
    firebase login

    Here, we are also logging into Firebase services. As a result, we will get the following success message:

    Successfully authenticate to Firebase
    Successfully authenticate to Firebase

    Then, by running the Firebase init command, we need to choose the required Firebase CLI feature function as shown in the screenshot below:

    Setup Firebase function
    Setup Firebase function

    Next, we need to choose the Firebase project as highlighted in the screenshot below:

    Select Firebase project on CLI
    Select Firebase project on CLI

    Now, we need to open the firebase functions folder by running the following command.

    code functions/

    Hence, we can now start implementing the Firebase project. The project structure is shown in the screenshot below:

    Firebase CLI project
    Firebase CLI project

    Now, in order to send the email, we are going to use Sendgrid. So, we need to install it first by running the following command:

    npm i @sendgrid/mail

    Next, we need to open the index. file and import firebase functions and Sendgrid main module. We also need to setup Sendgrid with a new API key as shown in the code snippet below:

    const functions = require('firebase-functions');
    const sgMail = require("@sendgrid/mail");
    sgMail.setApiKey("Sendgrid api key");

    Next, we need to call an event observer onCreate that will trigger when new data is added to the database as a new column that we define. Then, we need to call Sendgrid and send an email. The overall coding implementation for this is provided in the code snippet below:

    exports.sendEmailConfirmation = functions.database
       .ref('/feedback/{orderId}')
       .onCreate(async (snapshot, context) => {
           const val = snapshot.val();
           const mailOptions = {
               from: 'me@kriss.app',
               to: 'mymail@gmail.com',
               subject: 'Hey new message from ' + val.name+':'+val.email,
               html: '<b>' + val.message + '</b>',
           };
     
           sgMail
               .send(mailOptions)
               .then(res => {
                   return res.json({
                       result: "Success",
                       message: `Email has been sent to ${email}. `
                   });
               })
               .catch(res => {
                   // console.log('SIGNUP EMAIL SENT ERROR', err)
                   return res.json({
                       result: "error",
                       message: res.message
                   });
               });
           return null;
       });

    Finally, we send this function to Firebase by using the command provided below:

    firebase deploy

    And now, when we open the Function menu in the Firebase console, we will see the following configuration:

    Deploy function to Firebase
    Deploy function to Firebase

    Hence, if we submit the Feedback form again from our React Native app, we will get an email notification as shown in the emulator screenshot below:

    Send email from Sendgrid
    Send email from Sendgrid

    Hence, we have successfully implemented the Feedback screen with the form submit feature and also setup Firebase along with Sendgrid to send an email notification when the form is submitted.

    Conclusion

    In this chapter, we learned some important features and packages. First, we learned how to implement a form interface using the Formik package and validate it using the Yup package. Then, we got a detailed insight on how to set up Firebase on both Android and iOS platforms. Lastly, we also learned how to set up the Firebase Cloud Function and send email notifications using Sendgrid.

    All code available on Github.

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Krissanawat Kaewsanmuang
    • Website
    • X (Twitter)

    Developer Relation @instamobile.io

    Related Posts

    Building a Realtime Messaging app with React Native and Firebase

    March 20, 2023

    Build Real-World React Native App #11 : Pay For Remove Ads

    February 17, 2021

    Build Real-World React Native App #10 : Setup in-App Purchase in iOS

    February 1, 2021
    Leave A Reply Cancel Reply

    You must be logged in to post a comment.

    Stay In Touch
    • Facebook
    • Twitter
    • Pinterest
    • Instagram
    • YouTube
    • Vimeo
    Don't Miss
    Job March 5, 2019

    The Importance of Showing Off Your Soft Skills

    Hard (or technical) skills are easy to showcase. But what about soft skills and just how important are they?

    PostgreSQL vs MySQL: Is There a Clear Winner?

    October 25, 2019

    Git – Bad Practices

    September 20, 2016

    How Employment or Staffing Agencies Can Help You Find Web Development Work

    November 12, 2019

    Categories

    • AI & Automation
    • Angular
    • ASP.NET
    • AWS
    • B2B Leads
    • Beginners
    • Blogs
    • Business Growth
    • Case Studies
    • Comics
    • Consultation
    • Content & Leadership
    • CSS
    • Development
    • Django
    • E-commerce & Retail
    • Entrepreneurs
    • Entrepreneurship
    • Events
    • Express.js
    • Facebook Ads
    • Finance & Fintech
    • Flask
    • Flutter
    • Franchising
    • Funnel Strategy
    • Git
    • GraphQL
    • Home Services Marketing
    • Influencer & Community
    • Interview
    • Java
    • Java Spring
    • JavaScript
    • Job
    • Laravel
    • Lead Generation
    • Legal & Compliance
    • LinkedIn
    • Machine Learning
    • Marketing Trends
    • Medical Marketing
    • MSP Lead Generation
    • MSP Marketing
    • NestJS
    • Next.js
    • Node.js
    • Node.js Lessons
    • Paid Advertising
    • PHP
    • Podcasts
    • POS Tutorial
    • Programming
    • Programming
    • Python
    • React
    • React Lessons
    • React Native
    • React Native Lessons
    • Recruitment
    • Remote Job
    • SaaS & Tech
    • SEO & Analytics
    • Soshace
    • Startups
    • Swarm Intelligence
    • Tips
    • Trends
    • Vue
    • Wiki
    • WordPress
    Top Posts

    The Ultimate Guide to Drag and Drop Image Uploading with Pure JavaScript

    JavaScript December 27, 2019

    Navigating Remote Project Management Challenges: Best Practices

    JavaScript November 30, 2024

    Soshace Becomes an Informational Partner of NodeUkraine 2019

    Events May 14, 2019

    Уроки Express.js . Основы и Middleware. Часть 1.

    Programming November 22, 2016

    Subscribe to Updates

    Get The Latest News, Updates, And Amazing Offers

    About Us
    About Us

    Soshace Digital delivers comprehensive web design and development solutions tailored to your business objectives. Your website will be meticulously designed and developed by our team of seasoned professionals, who combine creative expertise with technical excellence to transform your vision into a high-impact, user-centric digital experience that elevates your brand and drives measurable results.

    7901 4th St N, Suite 28690
    Saint Petersburg, FL 33702-4305
    Phone: 1(877)SOSHACE

    Facebook X (Twitter) Instagram Pinterest YouTube LinkedIn
    Our Picks
    Startups

    Strategies for Maintaining Agility in Your Startup’s Growth

    Java

    Hunting Down and Fixing Memory Leaks in Java

    Interview

    Interview with Philipp

    Most Popular

    Leveraging Content Marketing Strategies to Propel Startup Growth

    Entrepreneurship

    Build Real-world React Native App #2: React navigation and React native vector icons

    React Native

    Broad Topics in Tech Podcasts — Part 4

    Podcasts
    © 2025 Soshace Digital.
    • Home
    • About
    • Services
    • Contact Us
    • Privacy Policy
    • Terms & Conditions

    Type above and press Enter to search. Press Esc to cancel.