Skip to content

Instantly share code, notes, and snippets.

@lmuntaner
Created April 27, 2017 12:30
Show Gist options
  • Save lmuntaner/72c088ba597b8c9365109d161b0a054f to your computer and use it in GitHub Desktop.
Save lmuntaner/72c088ba597b8c9365109d161b0a054f to your computer and use it in GitHub Desktop.
Redux Middleware for making requests
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