DEV Community

Kauna Hassan
Kauna Hassan

Posted on


Building Scalable Web Applications with React and Firebase

Firebase is a powerful platform that offers a variety of tools and services for quickly and easily developing web and mobile applications. React is a well-known JavaScript library for creating user interfaces. Combining these two technologies can aid in the development of scalable and efficient web applications. In this article, we will look at how to use React with Firebase.


Before we begin, ensure you have Node.js and Firebase installed on your system.

Step 1: Creating a new React project.

In order to use React with Firebase, we must first create a new React project. Run the following command in your terminal:

npx create-react-app my-app
cd my-app
npm start

Enter fullscreen mode Exit fullscreen mode

This will generate a new React project named my-app and launch the development server.

Step 2: Create a Firebase project.

The next step is to create a new Firebase project. Create a new project on the Firebase website. Set up the project and create a new Firebase application by following the instructions.

Step 3: Install the Firebase SDK.

In order to use Firebase in our React project, we must first install the Firebase SDK. To install the Firebase SDK, use the following command:

npm install firebase

Enter fullscreen mode Exit fullscreen mode

Step 4: Add Firebase to your React project.

To use Firebase's services, we must configure it in our React project. In your project's src folder, create a new file called firebase.js and add the following code:

import firebase from 'firebase/app';
import 'firebase/firestore';

const firebaseConfig = {
  apiKey: '<your-api-key>',
  authDomain: '<your-auth-domain>',
  projectId: '<your-project-id>',
  storageBucket: '<your-storage-bucket>',
  messagingSenderId: '<your-messaging-sender-id>',
  appId: '<your-app-id>',


export const db = firebase.firestore();

Enter fullscreen mode Exit fullscreen mode

In the firebaseConfig object, replace the placeholders with your own Firebase project credentials.

Step 5: Create a React component

Let's make a new React component to display Firebase data. Create a new file called Data.js in your React project's src folder. Include the following code in the file:

import React, { useState, useEffect } from 'react';
import { db } from './firebase';

function Data() {
  const [data, setData] = useState([]);

  useEffect(() => {
      .then((querySnapshot) => {
        const items = [];
        querySnapshot.forEach((doc) => {
  }, []);

  return (
      <h1>Data from Firebase:</h1>
        { => (
          <li key={}>{item.title}</li>

export default Data;

Enter fullscreen mode Exit fullscreen mode

This component retrieves data from the Firebase collection my-collection and displays it in a list.

Step 6: Compile the component

Let's use our React app to render the Data component. Add the following code to the App.js file in the src folder:

import React from 'react';
import Data from './Data';

function App() {
  return (
    <div className="App">
      <Data />

export default App;

Enter fullscreen mode Exit fullscreen mode

Step 7: Launch the app

Finally, let's launch the React app and view the Firebase data in our browser. Run the following command in your terminal:

npm start

Enter fullscreen mode Exit fullscreen mode

This launches the development server and launches your React app in your default browser. The data from Firebase should now be displayed in a list on your screen.


In this article, we learned how to use React with Firebase. We started with a new React project, installed the Firebase SDK, configured Firebase in our React project, added a new React component to fetch data from Firebase, and displayed the data in our React app. We can easily build powerful and scalable web applications by combining these two technologies. With the information in this article, you can begin developing your own React apps with Firebase integration.

Top comments (0)

Visualizing Promises and Async/Await 🤯

async await

☝️ Check out this all-time classic DEV post