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

Using console.log() within a method while chaining in JavaScript/jQuery

I've been experimenting with developing jQuery plugins and I'm interested in chaining methods. The jQuery tutorial (found here: https://learn.jquery.com/plugins/basic-plugin-creation/) mentions that you can chain methods by adding return this; at ...

The issue encountered is a TypeError stating that it is unable to retrieve properties of an undefined value, specifically in relation to the 'imageUrl

When I include the following line of HTML code: <td> <img align="center" [src]="productByBarCode.imageUrl" /> </td> An error is thrown by the console: ERROR TypeError: Cannot read properties of undefined (reading &a ...

Discovering the worth of specific selections in a dropdown menu

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> </head> <body> <select name="states" id="states"> <option value="100">Hawaii</option> <option value="107">Texa ...

Setting the value of a custom component property dynamically after the component has been rendered

I'm currently developing an Angular application and have a specific requirement to work on. I am using a custom component with 3 inputs, and I want to bind this custom component tag in the HTML of my page. <my-column [setInfo]="info" [dis ...

What are the steps to create a dynamic navigation menu in Angular 2?

I have successfully implemented this design using vanilla CSS and JS, but I am encountering challenges when trying to replicate it in Angular 2. Setting aside routing concerns, here is the current state of my component: navbar.component.ts import { Comp ...

Help! My express.js query is not functioning properly

I am facing an issue with a query in express.js. Citta_p and Citta_a are two arrays, and I need my query to return all the IDs for cities. However, it seems that only the last value is being returned, as if my cycle starts from var i = 1 and skips the valu ...

Revamp every single hyperlink that ends in .html

I am looking to customize the URLs on my website to appear like this: www.example.html/1 www.example.html/2 www.example.html/3 instead of their current format: www.example.html/1.html www.example.html/2.html www.example.html/3.html Can anyone provide a ...

React-Semantic-UI's Accordion component behaves differently when using the activeIndex prop with and without the exclusive={false} setting. See how it functions in both scenarios

Anticipated Outcome I am in need of a "closeAll" button that allows multiple lines to remain opened by setting exclusive={false}, however, this functionality does not seem to be working as expected. Actual Outcome Only when exclusive={true} is utilized ...

Running system commands using javascript/jquery

I have been running NodeJS files in the terminal using node filename.js, but now I am wondering if it is possible to execute this command directly from a JavaScript/jQuery script within an HTML page. If so, how can I achieve this? ...

The application of CSS transition fails in the context where top property is set as auto

I have been exploring an online tutorial that almost met my requirements. However, I encountered a challenge with the CSS 'transitions' effects. Basically, I need the text to be positioned at a specific distance from the top because the title wi ...

Exploring the Power of Angular Toastr Callback Functions

Hey there! I'm currently working with Angular Toastr to display messages on my screen. I have a setup where only two messages can be open at the same time - one for errors and another for warnings. These messages are persistent and require user intera ...

React Native Flatlist does not deselect onPress

In my app, I have a flat list that allows users to select items by touching a row. When a user touches a row, the item is selected and its id is stored in an array. However, when the user tries to un-select the item by touching it again, the item is not re ...

using hover/click functionality with a group of DIV elements

I have a group of DIV elements that I want to apply an effect to when hovering over them with the mouse. Additionally, when one of the DIVs is clicked, it should maintain the hover effect until another DIV is clicked. <div class="items" id="item1"> ...

When React object state remains unchanged, the page does not update automatically

i have a state object with checkboxes: const [checkboxarray_final, setCheckboxarray_final] = useState({ 2: ",4,,5,", 9: ",1,", }); i'm working on enabling check/uncheck functionality for multiple checkboxes: these are ...

What could be the possible reason for the controls in my element getting disabled due to adding a JavaScript background

First and foremost, I want to share a link with you to a page that I am currently developing so you can better understand the situation: Additionally, here is a link to the background effect: https://github.com/jnicol/particleground If you visit the page ...

Using multiple main.js files with RequireJs in Play Framework 2.1.1 Java: A step-by-step guide

While working on a single-page app with AngularJs + RequireJs in Play Framework 2.1.1, I encountered an issue regarding the structure of my application. The project consists of two main sections - an admin dashboard and a normal website - both housed withi ...

How can we optimize the organization of nodes in a group?

While many questions focus on grouping nodes based on similarity, I am interested in grouping nodes simply based on their proximity. I have a vast collection of densely packed nodes, potentially numbering in the millions. These nodes take up space on-scre ...

Getting the first validation message from Input in React: What you need to know

When using a number input with min and max values set, I have found that if a user enters a number above the max value, I can retrieve the validation message from event.target.validationMessage during the onChange event. This functionality works well when ...

Change Observable<String[]> into Observable<DataType[]>

I'm currently working with an API that provides me with an Array<string> of IDs when given an original ID (one to many relationship). My goal is to make individual HTTP requests for each of these IDs in order to retrieve the associated data from ...

lines stay unbroken in angular

I am encountering an issue when I execute the following code: DetailDisplayer(row) : String { let resultAsString = ""; console.log(row.metadata.questions.length); (row.metadata.questions.length != 0 )?resultAsString += "Questions ...