Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

100
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda