Redux thunk and asynchronous API calls
This commit is contained in:
parent
b556441459
commit
5ecf405fde
7 changed files with 64 additions and 2 deletions
|
@ -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 });
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue