Last active
August 22, 2018 20:08
-
-
Save thiagovilla/c9cfd88506c42eef0580f43e95599ca4 to your computer and use it in GitHub Desktop.
Triplet action creators for async API fetch in Redux
This file contains hidden or 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/ordersActions.js | |
export const FETCH_ORDERS_REQUEST = 'FETCH_ORDERS_REQUEST' | |
export const FETCH_ORDERS_SUCCESS = 'FETCH_ORDERS_SUCCESS' | |
export const FETCH_ORDERS_ERROR = 'FETCH_ORDERS_ERROR' | |
export const fetchOrdersRequest = _ => ({ // _ = () | |
type: FETCH_ORDERS_REQUEST | |
// no payload | |
}) | |
export const fetchOrdersSuccess = orders => ({ | |
type: FETCH_ORDERS_SUCCESS, | |
payload: { orders } // same as 'payload: { orders: orders }' | |
}) | |
export const fetchOrdersError = error => ({ | |
type: FETCH_ORDERS_ERROR, | |
payload: { error } | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment