Event driven updates with Firebase Functions triggered from Firestore updates

Event driven updates with Firebase Functions triggered from Firestore updates

Image a typical scenario, where a User would initiate an Action from the Frontend which would trigger an update on an administrative data set.

Image a typical scenario, where a User would initiate an Action from the Frontend which would trigger an update on an administrative data set. Of course, you could do the update straight ahead within the operation but could lead to longer operation time or even cause errors.

It should be a priority, to keep the UI/UX as smooth and fast as possible, therefore it is better to make only the least necessary action for the user and do any other tasks asynchronously.

Some examples for such administrative tasks could be the recalculation of a rank of a given item, or an NPS score.

Frontend Code — React or any other Framework

In this Scenario, we will focus on the NPS example.

import app from "firebase/app";
import "firebase/firestore";
class Firebase {
  constructor() {
    app.initializeApp(config);
    this.store = app.firestore();
  }
  trackNPSVote = async ({ score, comment = "" }) => {
    const NPSRef = this.store.collection("NPS");
    let autoID = await NPSRef.doc().id;
    const data = {
      score,
      createdAt: new Date().toISOString(),
      comment,
    };
    return await NPSRef.doc(`${autoID}`).set(data);
  };
}
export default Firebase;

Of course, something needs to call this code, imagine a simple UI with buttons from 1–10 and an optional comment field, on submit, call the trackNPSVote function.

firebase react firestore

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

How native is React Native? | React Native vs Native App Development

Article covers: How native is react native?, React Native vs (Ionic, Cordova), Similarities and difference between React Native and Native App Development.

React Native Firebase Firestore | Cloud Firestore Database

We take a look at the react native firebase cloud firestore database system and integrating firestore into our react native app.

How to Create Protected Routes in a React app with Firebase and react-router

Using Firebase and react-router to create protected routes in a react app.

What is firebase,firebase bangla tutorial.

LIKE | COMMENT | SHARE | SUBSCRIBE The Firebase Realtime Database is a cloud-hosted NoSQL database that lets you store and sync data between your users in re...

React Native Firebase Firestore | Cloud Firestore Database

We take a look at the react native firebase cloud firestore database system and integrating firestore into our react native app. Firestore is a NoSQL database that allows for real-time database updates that sync across applications, websites and more.