Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

99
Views
Wait for previous dispatch action to complete

const onFeedSubmit = async (data: PostFeedActionProps) => {
    try {
      setPostingFeed(true);

      selectedBusinessList.forEach(business => {
        apiUtils.postFeed(data, business.value).then(postResponse => {
          setFeeds(feeds => [postResponse, ...feeds]);

          const isInSameQuarter = isDateInCurrentQuarter(
            data.type === Type.CALL ? data.call.heldOn : data.meeting.heldOn
          );

          if (isInSameQuarter) {
            localDispatch(
              setThisQuarter({
                ...thisQuarter,
                totalActivities: thisQuarter.totalActivities + 1,
              })
            );
            if (!thisQuarterPostedEntities.includes(business.value)) {
              setThisQuarterPostedEntities([...thisQuarterPostedEntities, business.value]);
            }
          } else {
            localDispatch(
              setLastQuarter({
                ...lastQuarter,
                totalActivities: lastQuarter.totalActivities + 1,
              })
            );

            if (!lastQuarterPostedEntities.includes(business.value)) {
              setLastQuarterPostedEntities([...lastQuarterPostedEntities, business.value]);
            }
          }
        });
      });
      setSelectedBusinessList(() => []);
    } catch (e) {
      toast(
        // tslint:disable-next-line: max-line-length
        
      );
    } finally {
      setPostingFeed(false);
    }
  };

I am calling an API. Then after that I am updating totalActivities by 1 using dispatch action.

The problem is on UI it get only one update.

Basically it is not waiting for all dispatch action to get completed.

If I have 2 businesses then API is called twice and totalActivities should be increases by 2.

But here it is increment by 1 only.

How can I wait for all dispatch actions to get completed.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!