Description
What version of React, ReactDOM/React Native, Redux, and React Redux are you using?
- React: 18.2
- React Redux: 8.x (I'm able to reproduce this issue in all versions I've tried: 8.0.0, 8.0.5, and 8.1.2)
What is the current behavior?
I'm updating a project from react-redux 7.x to 8.x, and I think I'm running into a bug. I'm seeing a call to useSelector
with stale captured values. Here's a simplified project that demonstrates the issue: https://codesandbox.io/s/react-redux-8-closure-w8zqf4?file=/src/App.js
When the "Dispatch" button is clicked, the first useSelector
is called 5 times. All calls are expected except the third. The additional call would be fine except the captured variable now
has reverted back to its original value for that call--the second time it was called, it had already been updated. Note: if you open the console, you'll see a message about "captured stale data" that identifies the bad call to useSelector. In react-redux 7.x, this additional call isn't made.
What is the expected behavior?
Here's the exact same code with version 7.2.9 of react-redux: https://codesandbox.io/s/react-redux-7-closure-4lq8ph?file=/src/App.js
Which browser and OS are affected by this issue?
No response
Did this work in previous versions of React Redux?
- Yes