Side Effects in Action Creators

Learn about the side effects in action creators.

One of the most common approaches seen in online Redux tutorials is to handle side effects inside action creators using redux-thunk. The solution appears to be quite straightforward:

//Handling side effects with redux-thunk
const addItemToCart = item => (dispatch, getState) => {
  dispatch(updateCart(item));

  if (getState().cart.items.length > 10) {
    dispatch(applyDiscount(20));
  }

  dispatch(showNotification(`${item.name} has been added to cart!`));
}

Get hands-on with 1200+ tech skills courses.