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

476
Vistas
How to trigger action inside redux dispatch?

I've got an problem with redux. Here is my code:

actions.ts

export const getOrders = (id: string) => {
    return async (dispatch) => {
        const queryParams = {
            id,
            search: null,
            order: "DESC",
            status: "all"
        };

        const orders = await api.get('/api/orders', queryParams);
        dispatch(getOrdersSuccess(orders));
    }
}

export const getOrdersSuccess= (payload) => {
    return {
        type: 'GET_ORDERS_SUCCESS',
        payload
    };
}

someComponent.ts

  useEffect(() => {
      dispatch(getOrders(id)); //here is problem
  }, [dispatch, id])

can someone tell me why I cannot use getIncidents(id) function inside dispatch? When I put this function, VSCode throw me this error:

Argument of type '(dispatch: any) => Promise<void>' is not assignable to parameter of type 'AnyAction'.
  Property 'type' is missing in type '(dispatch: any) => Promise<void>' but required in type 'AnyAction'.ts(2345)

I have no idea how to fix this :/

thanks for any help!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Try waiting for promise to resolve , then dispatch your actions:

async/await :

useEffect(() => {
  (
    async function handleAsync() {
      let order = await getOrders(id)
      dispatch(order);
    }
  )()
}, [dispatch, id])

about 4 years ago · Juan Pablo Isaza 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