redux-small-axios-middleware

1.0.3 • Public • Published

redux-small-axios-middleware

Redux middleware for async request with axios

NPM

Build Status NPM version Downloads

install

npm i -S redux-small-axios-middleware

Usage

in createStore.js

import axios from 'axios';
import reduxSmallAxiosMiddleware from 'redux-small-axios-middleware';
 
let store = createStore(
  reducers, //custom reducers
  applyMiddleware(
    //all middlewares
    ...
    reduxSmallAxiosMiddleware(axios),
    ...
  )
)

in anyAction.js

export someActions = () => {
    return {
        type: 'GET_DATA_TEST', //require
        onSuccessCallbackfunction(){
            console.log("success")
        },
        onErrorCallback: function(){
            console.log("error")
        },
        options: { //
            url: '<your URL>', //require
        },
    }
}

Options object is axios request config

in dispaching.js

import { someActions } from '../anyAction.js'
 
//...
 
 
dispatch(someActions());

Package Sidebar

Install

npm i redux-small-axios-middleware

Weekly Downloads

1

Version

1.0.3

License

MIT

Last publish

Collaborators

  • alexfoxjs
  • zular