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

165
Vistas
Have to make synchronous calls from Button onClick in React

I have button which is making two calls in onClick, a function resetFilterItems which resets the filter in my state and simultaneously my getNetworkViewData is also api is also called.

I am not able to reset my filters firsts so making a call with incorrect payload. How can I first reset the filters props.filterStatus, props.filterCapabilities and then make a call synchronously in this situation?

               <Button
                type="secondary"
                onClick={() => {
                  props.resetFilterItems(
                    props.filterStatus,
                    props.filterCapabilities
                  );
                  props.getNetworkViewData(
                    getSearchQueryParam(),
                    props.partnerId
                  );
                }}
                size="medium"
              >
                Clear all
              </Button>
about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Try to call your another method in the resetFilterItems in this method.

So that way your state will clear and you can call another method after that.

Or share those 2 methods to get an idea more about your code flow.

You can use useEffect with your state dependencies. And call your Api in useEffect whenever you change your state.

useEffect(()=>{
                 props.getNetworkViewData(
                    getSearchQueryParam(),
                    props.partnerId
                  );
},[props.filterStatus])

Or you want to reset your states after API call then reset them in API response method.

about 4 years ago · Santiago Trujillo Denunciar
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