Skip to content

Instantly share code, notes, and snippets.

@mkrishnan-codes
Last active October 21, 2019 10:07
Show Gist options
  • Save mkrishnan-codes/8cccb5b686d976a03c6ee87fe9edf25a to your computer and use it in GitHub Desktop.
Save mkrishnan-codes/8cccb5b686d976a03c6ee87fe9edf25a to your computer and use it in GitHub Desktop.
const todoApp = combineReducers(reducers)
const store = createStore(
todoApp,
applyMiddleware(
UserPropsInjectorMiddleware,
// add all middlewares comma separated
// middleware1,
// middleware2 ...
)
)
const UserPropsInjectorMiddleware = (store: any) => (next: any) => (action: any) => {
// This will append userProps to all the actions called
// Store used here is an immutable state object, so store.getState()
// is an immutable object and need to use 'get' method to get attributes
// use store.getState().userData if it is a plain object
action.userProps = store.getState().get('userData')
const result = next(action)
return result
}
export default UserPropsInjectorMiddleware;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment