---
# System prepended metadata

title: '2001-GHP Cookie Jar: Redux'

---

# 2001-GHP Cookie Jar: Redux

Put your pending and outstanding questions here 👇
Make the question in H2 tag by using '##'

## Spread Operator Stuff

Redux has a guide: https://redux.js.org/recipes/using-object-spread-operator/

### Middleware Order

In extra credit of the middleware lab, why are we able to access and log the "next state" within the logging middleware? For example, this middleware gives us this console log statement: 
![](https://i.imgur.com/NBIbEi9.png)
![](https://i.imgur.com/E1TZ8YX.png)

but when blocking middleware is added, it doesn't work:
![](https://i.imgur.com/g8mlpSm.png)
![](https://i.imgur.com/crXCRbL.png)

I can see that the first console log happens, then the block, then setState log, but I don't understand why.

## Answer

This is because of `next`. As soon as we call `next`, we send the action to the next middleware in our chain, which in this case, is block. So, then, in block, it sets the `action.type` to `blocked` which you see then "dispatching blocked" and then in block, it sends the action with its new type "blocked" to the next middleware which doesn't exist so then it gets sent to the reducer since middleware sits in between the action sent and the reducer. At which point, our amount has not been updated. And then the console.log trying to print the next state will print out with an un-updated balance. 

For more info, check out this really in depth [blog post](https://medium.com/@meagle/understanding-87566abcfb7a) and also the [Redux Middleware Documentation](https://redux.js.org/advanced/middleware/)