Created
April 27, 2017 12:30
-
-
Save lmuntaner/72c088ba597b8c9365109d161b0a054f to your computer and use it in GitHub Desktop.
Redux Middleware for making requests
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
const createRequestMiddleware = baseUrl => ({ dispatch }) => next => action => { | |
if (action.type !== 'api') { | |
return next(action) | |
} | |
const url = `${baseUrl}${action.url}`; | |
return fetch(url) | |
.then(res => res.json()) | |
.then(data => action.success(dispatch, data)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment