0.0.1 • Published 8 years ago

redux-thunk-inject v0.0.1

Weekly downloads
780
License
MIT
Repository
github
Last release
8 years ago

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