0

Installed firebase via command npm i firebase. Also tried npm i firebase@8.1.1 (Nov2020 version in which the tutorial has used firebase) and npm i firebase --save to no avail.

Here is my Stackblitz project link for your reference.

S.O.S.

enter image description here

Eldwin
  • 169
  • 2
  • 14

1 Answers1

1

Please have a look at the documentation: https://firebase.google.com/docs/web/setup

Your firebase.js should look like this

import { initializeApp } from 'firebase/app';
import { getFirestore } from 'firebase/firestore/lite';

const firebaseConfig = {
  apiKey: 'AIzaSyCUCwjxhnH-D99j1dKmI-tyL3Q057FI1WA',
  authDomain: 'cp-react-robinhood.firebaseapp.com',
  projectId: 'cp-react-robinhood',
  storageBucket: 'cp-react-robinhood.appspot.com',
  messagingSenderId: '112144437320',
  appId: '1:112144437320:web:bf5dd8d3a3f0d83bc6c87d',
  measurementId: 'G-NLE375QG7B',
};
const firebaseApp = initializeApp(firebaseConfig);
const db = getFirestore(firebaseApp);

export { db }; 

Your Stats.js should start like this:

import React, { useState, useEffect } from 'react';
import './Stats.css';
import axios from 'axios';
import StatsRow from './StatsRow';
import { db } from './firebase';
import { collection, getDocs } from 'firebase/firestore/lite';

// f u
function Stats() {
  const TOKEN = 'bvkgi0v48v6vtohioj2g';
  const BASE_URL = 'https://finnhub.io/api/v1/quote';
  const [stockData, setstockData] = useState([]);
  const [myStocks, setmyStocks] = useState([]);
  const getMyStocks = () => {
    const myStocksCollection = collection(db, 'cities');
    getDocs(myStocksCollection).then((snapshot) => {
      let promises = [];
      let tempData = [];
      snapshot.docs.map((doc) => {
        console.log(snapshot.docs);
        promises.push(
          getStocksData(doc.data().ticker).then((res) => {
            tempData.push({ id: doc.id, data: doc.data(), info: res.data });
          })
        );
      });
    });
  };

You just imported firebase the wrong way. You have to import each module which you will need for you purpose.

Alex
  • 50
  • 1
  • 6
  • Ok, i've read through the sdk and it was really helpful when compared with your code. i added in your code and changed the collection name from 'cities' to 'myStocks' which is the collection name in firestore db. now im getting a new error: https://stackoverflow.com/questions/69860046/firebase-firestore-error-rpc-error-http-error-has-no-status – Eldwin Nov 05 '21 at 22:54