-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stale values in useSelector closure #2060
Comments
This was referenced Jan 5, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What version of React, ReactDOM/React Native, Redux, and React Redux are you using?
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.jsWhen 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 variablenow
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?
The text was updated successfully, but these errors were encountered: