Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import config from "./config";
export const requestProducts = () => ({
type: "REQUEST_PRODUCTS"
});
export const receiveProducts = products => ({
type: "RECEIVE_PRODUCTS",
products
});
export const fetchProducts = () => dispatch => {
dispatch(requestProducts());
return fetch(config.API_PRODUCTS_URL)
.then(response => response.json())
.then(json => dispatch(receiveProducts(json)))
.catch(() => {
dispatch(receiveProducts([]));
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.