Skip to content

Instantly share code, notes, and snippets.

@thiagovilla
Last active August 22, 2018 13:49
Show Gist options
  • Save thiagovilla/aa0eaa9292c59a8d27a7508177c62343 to your computer and use it in GitHub Desktop.
Save thiagovilla/aa0eaa9292c59a8d27a7508177c62343 to your computer and use it in GitHub Desktop.
Fetch thunk with Redux dispatch() and triplet async actions (request, success, error)
// duck/ordersFetch.js
import { getOrders } from '../api/orders'
import {
fetchOrdersRequest, // 'request' or 'begin'
fetchOrdersSuccess,
fetchOrdersError // 'error' or 'failure'
} from './ordersActions'
const fetchOrders = params =>
dispatch => {
dispatch(fetchOrdersRequest())
getOrders(params)
.then(orders => dispatch(fetchOrdersSuccess(orders)))
.catch(error => dispatch(fetchOrdersError(error)))
}
export default fetchOrders
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment