Guest User

Untitled

a guest
Jul 10th, 2022
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Full Home.js Code
  2.  
  3. import React, { useEffect, useState } from "react";
  4. import { getDocs, collection, deleteDoc, doc } from "firebase/firestore";
  5. import { auth, db } from "../firebase";
  6. import { withRouter } from "react-router-dom";
  7. import { Link } from "react-router-dom";
  8. import App from "../App";
  9. import { Stack } from "@mui/material";
  10. import { useNavigate } from "react-router-dom";
  11.  
  12. function Home({ isAuth }) {
  13.   let navigate = useNavigate();
  14.   const [postLists, setPostList] = useState([]);
  15.   const postsCollectionRef = collection(db, "posts");
  16.  
  17.   useEffect(() => {
  18.     const getPosts = async () => {
  19.       const data = await getDocs(postsCollectionRef);
  20.       setPostList(data.docs.map((doc) => ({ ...doc.data(), id: doc.id })));
  21.     };
  22.  
  23.     getPosts();
  24.   }, []);
  25.   return postLists.map((post, key, index) => {
  26.     return (
  27.       <div className="App">
  28.         {isAuth && post.author.id === auth.currentUser.uid && (
  29.    
  30.           <div className="post">
  31.             <img className="postimage" src={post.link} />
  32.           </div>
  33.          
  34.         )}
  35.       </div>
  36.     );
  37.   });
  38. }
  39.  
  40. export default Home;
  41.  
  42.  
  43. App.css
  44.  
  45. .postimage{
  46.   width: 100px;
  47.   height: 100%;
  48.   display: flex;
  49.   justify-content: center;
  50.   align-items: center;
  51. }
  52.  
  53. .post{
  54.   width: 100%;
  55.   display: flex;
  56.   justify-content: center;
  57.   flex-direction: row;
  58.   align-items: center;
  59. }
  60.  
Advertisement
Add Comment
Please, Sign In to add comment