Last active
November 9, 2018 19:27
-
-
Save tvaisanen/d758043664be5e014e18e233fc9ecb6c to your computer and use it in GitHub Desktop.
This file contains 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 productActions from '../../state/search-results/search-results.actions'; | |
export function makeSearch(keyword) { | |
// by using redux-thunk middleware | |
// async redux action can be handled | |
return function (dispatch, getState) { | |
// get the promise | |
const promise = fetch("http://api.url/"); | |
// when promise has something to offer | |
promise.then(response => | |
// forward the response further | |
return response.json(); | |
}).then(results => { | |
// do the required actions with the results | |
dispatch(productActions.addProducts(results)) | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment