Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Display all posts from database

useEffect(() => {
    const getPostData = async () => {
      const q = collection(db, "posts");
      const docSnap = await getDocs(q);
      const promises = docSnap.docs.map(async (item) => {
        const tmp = collection(db, "posts", item.id, "userPosts");
        const tmpSnap = await getDocs(tmp);
        return tmpSnap.docs.map((element) => element.data());
      });
      const arrayOfPosts = await Promise.all(promises);
      let newPosts = [];
      arrayOfPosts.forEach((posts) => {
        newPosts = [...newPosts, ...posts];
      });
      setPosts(newPosts);
    };

    getPostData().catch(console.error);
    return;
  }, []);
Comment

PREVIOUS NEXT
Code Example
Javascript :: Using useEffect with async 
Javascript :: Delete a field from Firebase Firestore where the field/key has a period/punctuation (".") - modular v9 JavaScript SDK 
Javascript :: Reanimated2 interpolateNode to animate opacity error "undefined is not an object 
Javascript :: Difficulties handling asynchronous taks using image-picker and copying files in react-native 
Javascript :: how to make colspan of table footer flexible with javascript/jQuery 
Javascript :: How to check the increase/decrease of letter input in pasting clipboard in jQuery 
Javascript :: ERROR Error: Uncaught (in promise): NullInjectorError: R3InjectorError(AuthModule)[AuthService - AuthService - AngularFirestore - InjectionToken 
Javascript :: I have a dataframe with a json substring in 1 of the columns. i want to extract variables and make columns for them 
Javascript :: how to build a nested, dynamic JSON in Go 
Javascript :: How to access a preexisting collection with Mongoose 
Javascript :: filter data nodejs 
Javascript :: nextjs app wdyr 
Javascript :: export from json 
Javascript :: Printer Errors 
Javascript :: online convert javascript to typescript 
Javascript :: phaser rotate matrix 180 
Javascript :: Jquery JavaScript Prevent From Press Enter Key Keyboard 
Javascript :: how to get content disposition from header jquery 
Javascript :: javascript ls 
Javascript :: what does the text before an object stand for in js 
Javascript :: Calculator for two numbers 
Javascript :: Toggle child element onclick of parent element 
Javascript :: prisma is and isNot 
Javascript :: docker healthcheck express 
Javascript :: Backbone View Event 
Javascript :: remove T from datetime in js 
Javascript :: Top Tips for Vue 3 Development 
Javascript :: filter function in javascript 
Javascript :: object.map() nest js 
Javascript :: dom traversal jquery 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =