DEV Community

Ibrahim Shamma
Ibrahim Shamma

Posted on • Edited on

1 2 1 1 1

asyncdispatch is now on npm packages!

async-dispatch middleware

npm

async-dispatch is a middleware can be added with no time to privilage the asynchronous into your store

For more informatiom about the future of redux-logger, check out the discussion here.

Table of contents

Install

npm i --save async-dispatch

Usage

import asyncDispatchMiddleware from "async-dispatch";
import { createStore } from "redux";
import { applyMiddleware } from "redux";

const store = createStore(
  rootReducer,
  applyMiddleware(asyncDispatchMiddleware)
);
// Note passing middleware as the third argument requires redux@>=3.1.0
Enter fullscreen mode Exit fullscreen mode

Then applying this middleware is simple as

const LoginReducer = (state = intialState, action) => {
      login(action.userData).then((data) => {
        if (data.error) {
          action.asyncDispatch({
            type: actionTypes.ERROR,
            message: data.error,
          });
        } else {
          action.asyncDispatch({
            type: actionTypes.SUCCESS,
            user: data,
            message: "Logged successfully",
          });
        }
      });
      return { ...state };
})

Enter fullscreen mode Exit fullscreen mode

To Do

  • [ ] Adding types

License

MIT

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay