react-usemiddleware icon indicating copy to clipboard operation
react-usemiddleware copied to clipboard

Stale state with plain actions

Open afonsoduarte opened this issue 6 years ago • 0 comments

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.

afonsoduarte avatar Feb 22 '19 08:02 afonsoduarte