Skip to content

Instantly share code, notes, and snippets.

@jks8787
Last active August 2, 2017 21:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jks8787/6c1bcd1a8d3c21737bdd13968da2ee67 to your computer and use it in GitHub Desktop.
Save jks8787/6c1bcd1a8d3c21737bdd13968da2ee67 to your computer and use it in GitHub Desktop.
actions and types for react+ redux -- Medium Article gist
import * as types from './actionTypes';
function url() {
return 'www.url.com';
}
export function receiveStuff(json) {
return {type: types.RECEIVE_STUFF, stuff: json.stuff};
}
export function fetchStuff() {
return dispatch => {
return fetch(url(), {
method: 'GET',
mode: 'cors',
credentials: 'include',
headers: {
'x-api-key': apiKey,
'Accept': 'application/json'
}
})
.then(response => response.json())
.then(json => dispatch(receiveStuff(json)));
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment