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

97
Vistas
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 Respuestas
Responde la pregunta

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