Created
October 28, 2016 14:00
-
-
Save bneiluj/e20df3e3e3aa505a4bf6045d1be8be65 to your computer and use it in GitHub Desktop.
React Redux - Fetching asynchronous data without using Thunk
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
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