Skip to content

Instantly share code, notes, and snippets.

@christianchown
Last active December 5, 2019 21:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save christianchown/73a5ebc914e5303e0a00833c82cd3109 to your computer and use it in GitHub Desktop.
Save christianchown/73a5ebc914e5303e0a00833c82cd3109 to your computer and use it in GitHub Desktop.
Custom async Redux middleware
const userMiddleware = ({ getState, dispatch }) => next => async action => {
const result = next(action);
switch (action.type) {
case SOME_ACTION:
const asyncResult = await somethingAsync();
dispatch(anotherAction(asyncResult));
break;
case SOME_OTHER_ACTION:
const { slice: { stateVariable } } = getState();
await someProcess(stateVariable);
break;
}
return result;
}
@plandem
Copy link

plandem commented Dec 5, 2019

omg, that gist is like meeting of old friends now. Before it was @Constantiner and now @markerikson (hello, redux-orm) :)))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment