Last active
October 21, 2019 10:07
-
-
Save mkrishnan-codes/8cccb5b686d976a03c6ee87fe9edf25a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const todoApp = combineReducers(reducers) | |
const store = createStore( | |
todoApp, | |
applyMiddleware( | |
UserPropsInjectorMiddleware, | |
// add all middlewares comma separated | |
// middleware1, | |
// middleware2 ... | |
) | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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