0

Here is my code, the same code used to work with the older version of firebase but now as I try to connect my React.js app to retrieve data from the database, it returns an empty screen and the console does not show any error messsage

App.js:

import { useEffect, useState } from "react";
import "./App.css";
import Post from "./Post";
import {db} from "./firebase";

function App() {
  
  const [posts, setPosts]=useState([]);

  useEffect(()=> {
    db.collection('posts').onSnapshot(snapshot => {
      
      setPosts(snapshot.docs.map(doc => doc.data() ))
    })

  }, []);


  
  return (
    <div className="app">
      <div className="app__header">
        <img
          className="app__headerImage"
          src="https://www.instagram.com/static/images/web/mobile_nav_type_logo.png/735145cfe0a4.png"
          alt=""
        />
      </div>
      


      {
        posts.map(post => (
          <Post username={post.username} caption={post.caption} imageUrl={post.imageUrl} />
        ))
      }
    </div>
  );
}

export default App;
Frank van Puffelen
  • 499,950
  • 69
  • 739
  • 734
  • classic React Hooks async problem, see this -> https://stackoverflow.com/questions/53332321/react-hook-warnings-for-async-function-in-useeffect-useeffect-function-must-ret – Zhang YH Apr 26 '22 at 01:57

0 Answers0