Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

475
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda