-
-
Save jks8787/6c1bcd1a8d3c21737bdd13968da2ee67 to your computer and use it in GitHub Desktop.
actions and types for react+ redux -- Medium Article gist
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 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