Redux thunk and asynchronous API calls

This commit is contained in:
Rodrigo Pedroso 2019-06-19 17:08:53 -04:00
commit 5ecf405fde
7 changed files with 64 additions and 2 deletions

View file

@ -3,3 +3,13 @@ import { ADD_ARTICLE } from "../constants/action-types"
export function addArticle(payload) {
return { type: ADD_ARTICLE, payload }
}
export function getData() {
return function(dispatch) {
return fetch("https://jsonplaceholder.typicode.com/posts")
.then(response => response.json())
.then(json => {
dispatch({ type: "DATA_LOADED", payload: json });
})
}
}