Waiting for all promises to resolve: A step-by-step guide

I need to make two different API calls and perform calculations based on the results of both. To wait for both promises to resolve, I am using Promise.all().

const getHashTagList = async () => {
    loader.start();
    try {
      await getAllHashTags().then((response) => {
        setHashtagList([...response?.data]);
      });
    } catch (err) {
    } finally {
      loader.stop();
    }
  };
  
  
 const getUserFollowingHT = async () => {
    loader.start();
    try {
      await getUserDetails().then((response) => {
        setUserFollowingHT([...response?.data?.followingHashtags]);
      });
    } catch (err) {
    } finally {
      loader.stop();
    }
  };

To call these 2 promises, I am using the following syntax:

useEffect(() => {
    //getHashTagList();
    // getUserFollowingHT();
    Promise.all([getHashTagList, getUserFollowingHT]).then(
      (combineResp) => {
        console.log(combineResp);
      }
    );
  }, []);

However, I am encountering a problem where the output shows function declaration syntax instead of calling those promises successfully.

Answer №1

Give this a shot

tryEffect(() => {
  (async () => {
    const data = await Promise.all([fetchTags, fetchUserFollowing]);
    console.log(data);
  })();
}, []);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is it possible to assign the margin-bottom property of one element to be equal to the dynamic height of a sibling element?

I am in the process of creating a website that features a fixed (non-sticky) footer placed behind the main content using the z-index property. The footer only becomes visible when the user scrolls to the bottom of the page, achieved by assigning a margin-b ...

I am finding that the text I am creating using context.fillText keeps getting distorted within the canvas

I am attempting to place text inside a canvas element. The HTML markup for the canvas is as follows: <canvas id="leaderboard2" style="position: fixed; right: 1250px; top: 140px; width: 230px; height: 330px;"></canvas>. Des ...

Achieving optimal hardware performance for WebGL compatibility is essential

Lately, I have been exploring the world of Three.js to create impressive 3D scenes in WebGL. To ensure compatibility for all users, I have also developed versions using Three's CanvasRenderer which may not be as detailed but can still function on brow ...

What is the method for setting the content-type in an AJAX request for Android browsers?

I am facing an issue with my ajax call to the Rails server. The response from the server varies between HTML and JSON based on the content type. Surprisingly, this works smoothly on iPhone and desktop browsers like Chrome, but I am encountering a problem o ...

Improving code quality and consistency in Javascript: Tips for writing better code

Hey, I've been experimenting with some code using ajax and have ended up with a lot of repetitive lines. Is there a way to streamline the code without losing functionality? I keep using the .done method multiple times when I could probably just use it ...

Establish the Central European Time (CET) timezone using the toISOString

Has anyone figured out how to convert a MYSQL timestamp date to a JS date using toISOString() and adjusting the time-zone to CET? I have been trying to achieve this with the following code, which currently produces the format "2021-02-251 15:27:20" - howev ...

Breaking up a string using regex with various conditions

(Javascript old version of Node.js) Update: I need to clarify my request. I have a variety of instances like these var name1; CONST name2 Let nam; leT nam VAr n1 ; What I want as output is name1 name2 nam nam n1 Therefore, I am ex ...

Enhancing user experience with Jquery datepicker and executing multiple actions on select

I am working on a form that includes a jQuery date selector and radio buttons structured in a table as shown below: <table> <tr> <td> <input type="text" id="5506_datepick_1"></input> </td> <td&g ...

``Can you help me understand how to display two different values in the same field

import React, { Component } from 'react' import DatePicker from 'material-ui/DatePicker'; class CombinedDateField extends Component { state = { first:'', second:'', } handleChangeFirstEventDate = (event, ...

Tips for navigating to a specific row within a designated page using the Angular Material table

Utilizing angular material, I have set up a table with pagination for displaying data. When a user clicks on a row, they are redirected to another page. To return to the table page, they must click on a button. The issue arises when the user needs to retu ...

Do you have any suggestions on how to fix this npm SQLite installation issue?

Could use some help with an SQLite installation error I'm encountering. Any ideas on what the issue might be and how to resolve it? C:\Users\jacka\Downloads\discord-emoji-stealer-master\discord-emoji-stealer-master>npm i & ...

Angular is used to call a function that captures a specific div and then waits for the capture to be completed before

I'm facing a challenge where I need to handle the capturing of a div using a method called capture() within another method. Take a look at the code snippet below: theimage; // declaring the variable callcapture() { // perform certain actions t ...

Why does my function consistently notify me that my answer is incorrect?

I've created a fun Pi quiz function that awards half a point for each correct digit you type. However, even if I enter just '3', it always shows as incorrect. Can someone assist me with this issue? function pi() { var piWithoutDecimals ...

Tips for maximizing the effectiveness of the .bind(this) method in Meteor js

Hey there, I've got a question for you. How do we go about using the bind method in Meteor? Take a look at this code snippet below. It feels like there's some repetition going on that bothers me. Thank you so much for sharing your thoughts! Bi ...

In need of assistance with filtering lists using JQuery

Hi there! I'm looking to modify a list filtering function by targeting multiple ul tags within the same div instead of just filtering li elements. Any ideas on how this can be achieved? Below is my JavaScript code: $( document ).ready(function() { ...

Optimal approach for creating a CSS button with a dynamic size, gradient background and arrow design

I'm utilizing the Zurb Foundation framework and aiming to create dynamic call-to-action buttons with varying sizes, text, a background gradient, and a right-pointing arrow. There are three potential approaches I've envisioned: Employ an a el ...

Exploring Next.js: Leveraging fetch to retrieve data in getServerSideProps and passing it to the client via query parameters

I'm utilizing a getServerSideProps function on the directory page. pages/catalog/index.js export async function getServerSideProps(ctx) { const response = await fetch( `http://someDomen.com/api/ipro/catalog?${ctx?.query?.page ? `page=${ctx.quer ...

As soon as the TextInput is tapped, the keyboard disappears abruptly

I designed a basic component for a text input that appears like this (without any styling) import { FC } from "react" import { TextInput, TextInputProps, View } from "react-native" interface IProps { value: string, setValue: (a ...

Having trouble adding global method using Plugin in Vue 3?

I have been working on creating a method that can generate local image URLs to be used in any template automatically. However, I encountered an issue while trying to develop a plugin that adds a global property. Plugin Implementation: // src/plugins/urlb ...

How to Retrieve Data from an HTML Table using the Laravel Framework

I have a unique and interactive Dynamic Sortable Table where I can effortlessly add or delete rows likethis uploaded image here. There is an intriguing loop in my controller that runs precisely 4 times, based on the number of columns in the table. However, ...