redux-thunk-inject

0.0.1 • Public • Published

Redux Thunk Inject

A drop-in replacement for redux-thunk that let's you inject additional variables into your action creators.

Installation

npm install --save redux-thunk-inject

Then use with applyMiddleware():

import { createStore, applyMiddleware } from 'redux'
import thunkInject from 'redux-thunk-inject'
import rootReducer from './reducers/index'

const contextualApi = {
  something: 'for the current user only, necessary in action creators'
}

const other = 'other'

const store = createStore(
  rootReducer,
  applyMiddleware(thunkInject(contextualApi, other /*, ...*/))
)

Then in your async action creators:

export function createUser () {
  return (dispatch, getState, contextualApi, other) => {
    contextualApi.createUser().then(() => {
      dispatch('USER_CREATED');
    })
  }
}

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i redux-thunk-inject

Weekly Downloads

263

Version

0.0.1

License

MIT

Last publish

Collaborators

  • vesln