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

473
Views
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 answers
Answer question

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 Report
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!