react-usemiddleware
react-usemiddleware copied to clipboard
Stale state with plain actions
The getState function passed to the middleware returns stale state after you dispatch a plain action. You can see the example here:
https://codesandbox.io/s/xl3jxokwm4
If you click the counter and check the console, you will see that both prev state and next state display the same value.
I'm guessing that this is because render is async, so dispatching an action doesn't necessarily immediately invoke a re-render?
This does not happen with thunks however, which is why your example works fine.