Last active
August 22, 2018 13:49
-
-
Save thiagovilla/aa0eaa9292c59a8d27a7508177c62343 to your computer and use it in GitHub Desktop.
Fetch thunk with Redux dispatch() and triplet async actions (request, success, error)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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