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

96
Views
Dispatch action from actionCreator

I studied the react redux example (shopping cart) and saw this implementation of action addToCart.

The question is, where do the dispatch and getState arguments come from?

export const addToCart = productId => (dispatch, getState) => {
  if (getState().products.byId[productId].inventory > 0) {
    dispatch(addToCartUnsafe(productId))
  }
}

I tried to copy it in my example, but I can't get it to work.

PS: i can make this with mapDispatchToProps in my example

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

They come from the thunk middleware. It allows redux action creators to not only return simple objects (with a type property), but also async functions. The middleware calls these async functions and passes dispatch and getState as arguments. Which in turn allows you to dispatch multiple other actions, look at the current state, and generally have precise control over async flow. Thunk is just one of many middlewares that support async stuff within redux actions.

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!