rah

redux-api-handling-middleware

Redux middleware for api call

Showing:

Popularity

Downloads/wk

5

GitHub Stars

0

Maintenance

Last Commit

2yrs ago

Contributors

1

Package

Dependencies

0

Size (min+gzip)

0.5KB

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

Redux Api Middleware

npm version npm downloads

Redux Api middleware enables robust handling of async code in Redux. The middleware enables optimistic updates and dispatches success and failed actions. It can be used to chain async actions. It allows you to write action creators that return a function instead of an action, you can dispatch more than action in the action creator function.

Installation

npm i redux-api-handling-middleware

Docs and Help

Usage

import apiMiddleware from  'redux-api-handling-middleware';
import axios from 'axios';

const middleware = applyMiddleware(apiMiddleware.withClient(axios));
const store = createStore(reducer, middleware);
//sample ACTION
export function getSeatLayout() {
  return (dispatch) => {
    dispatch({
      type: 'FETCH_LAYOUT',
      promise: client => client.get('/layout'),
    });
    dispatch({
      type: 'UPDATE_SEAT_REQ',
      noOfSeats: 2,
    });
  };
}

After dispatching action of type FETCH_LAYOUT our middleware automatically dispatches FETCH_LAYOUT_SUCCESS and FETCH_LAYOUT_FAILED according to the api response.


Copyright (c) 2017 Pranav TV. Licensed with The MIT License (MIT).

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100