Skip to content

Instantly share code, notes, and snippets.

@tvaisanen
Last active November 9, 2018 19:27
Show Gist options
  • Save tvaisanen/d758043664be5e014e18e233fc9ecb6c to your computer and use it in GitHub Desktop.
Save tvaisanen/d758043664be5e014e18e233fc9ecb6c to your computer and use it in GitHub Desktop.
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