Skip to content

Instantly share code, notes, and snippets.

@bneiluj
Created October 28, 2016 14:00
Show Gist options
  • Save bneiluj/e20df3e3e3aa505a4bf6045d1be8be65 to your computer and use it in GitHub Desktop.
Save bneiluj/e20df3e3e3aa505a4bf6045d1be8be65 to your computer and use it in GitHub Desktop.
React Redux - Fetching asynchronous data without using Thunk
import * as constants from './../constants';
import axios from 'axios';
import config from './../config';
function fetchProductsType(products) {
return {
type: constants.FETCH_PRODUCTS,
payload: products
};
}
export function fetchProducts(dispatch) {
axios.get(`${config.url.apiPublicMock}/products`)
.then(response => {
dispatch(fetchProductsType(response.data.products));
});
return {
type: 'Loading products'
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment