asynchronous dispatch is now on npm packages!
June 5, 2020 • ☕️ 1 min read
React Redux Javascript
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.0Then 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 };
})To Do
- Adding typeScript types
License
MIT