Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Don't use redux-saga
const promiseMiddleware = store => next => action => {
if (typeof action.then === 'function') {
return Promise.resolve(action).then(next);
} else if (action.value && typeof action.value.then === 'function') {
return Promise.resolve(action.value).then(value => next({ type: action.type, value }));
}
// else, not a promise
try {
return next(action);
} catch (e) {
return Promise.reject(e);
}
};
// dispatch(someQuery())
// dispatch(fechApi('/foos').then(foos => ({type: FOOS, value: foos})))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.