Skip to content
This repository has been archived by the owner on Feb 21, 2023. It is now read-only.

producthunt/redux-thunk-inject

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Enhanced thunk middleware for Redux

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published