In this guide it will be presented to the reader the basic concept of Redux Middleware.
If the reader is already experienced with [node.js] and it's server side libraries like [Express] or [Koa], it should by now be familiar with the concept of middleware.
Either in any of the above libraries, middleware is a piece of code that resides between the framework's incoming request and the response sent.
For example some third party middlewares that can be applied to both these frameworks are :
* [Helmet] - For some measure of security to applications
* [Wiston] - For logging purposes
* [Compression] - For compression of HTTP responses
## Redux Middleware
In Redux, the middleware works in a similar pattern as described above, but addresses different problems.
Here the middleware is a piece of code that intercepts every single action that comes through and modifies that specific action or cancel it altogether.
Redux middleware are just functions with the signature
```js
const reduxMiddleware = store => next => action => {
// do some middleware stuff
}
```
Side Note - The fact that this is a function that takes a store and returns a function that takes a next callback and returns a function that takes an action and performs some middlware operations might look a bit odd. why do that instead of three parameters? Well this is actually a very helpful technique from functional programming called currying and it enables a lot of goodness like partial application. The main difference though is how you call the middleware function.
```js
// calling an uncurried version - NOT how you call the function above
reduxMiddleware(store, next, action)
// vs calling the curried version - how you call the function above
1.) store - your redux store and calling its "getState" method returns the current state of your store.
```js
let currentState = store.getState()
```
2.) next - a callback that you pass an action to continue with the flow of your redux middleware / reducers.
```js
next(action)
```
3.) action - the action dispatched to the store to update state
Let's use the information above to create a simple logging middleware that will log "User Updated!" to the console every time an action with type "UPDATE_USER" is dispatched.
```js
const updateUserLogger = store => next => action => {
[//]: # (These are reference links used in the body of this note and get stripped out when the markdown processor does its job. There is no need to format nicely because it shouldn't be seen. Thanks SO - http://stackoverflow.com/questions/4823468/store-comments-in-markdown-syntax)