-
-
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
Component does not re-render when changing a value #2071
Comments
Still running into this one and it's super strange (and not easy to recognize in most cases). Looking at the linked codesandbox, if we comment out the local state change, it works as expected: const [lastSortDirection, setLastSortDirection] = useState(sortDirection);
if (lastSortDirection !== sortDirection) {
// Setting state directly in the render method is an approach recommended in the react docs:
// https://react.dev/learn/you-might-not-need-an-effect#adjusting-some-state-when-a-prop-changes
// setLastSortDirection(sortDirection);
} With that line uncommented, the action seems to be dispatched properly, the reducer appears to function, the redux store seems to be updating as expected - but the component isn't re-rendering. I was thinking it could be an issue with cc: @markerikson |
Unfortunately this is low priority for me atm. All my attention is focused on getting RTK 2.0 and the associated major versions out the door. My first guess would be something about |
Thanks for taking the time to look at this and also for suggesting a direction. I appreciate the response. |
Looking into this a bit, I noticed that the issue occurs when setting state back to its initial value. If we change the initial value to something other than That led me to react issue #25565, which appears to be merged, but describes the issue exactly:
So I created a reproduction that doesn't use redux in any way, based on a test that was referenced in that issue and it seems like this is in fact an issue with react, but one that will be fixed in 18.3.0 (switching between 18.2.0 and the latest 18.3 canary release toggles between broken and fixed): https://codesandbox.io/s/react-not-rerendering-v32s9x?file=/src/App.js As a sanity check, I tried switching react and react-dom from 18.2.0 to the latest 18.3 canary in the codesandbox provided by @dylanwulf and the behavior works as expected. |
Yeah, I wondered if it was something like that. I knew I'd seen a couple issues along those lines (and ironically I seem to have commented in that one), but dind't remember specifics. |
Oh nice find, that does sound like the same issue |
Just to keep this issue updated, the newly released react version |
What version of React, ReactDOM/React Native, Redux, and React Redux are you using?
What is the current behavior?
I have a value in my redux store and a component subscribed to that value via
useSelector
. I have encountered a scenario where changing the value does not re-render my component: https://codesandbox.io/s/react-redux-not-re-rendering-on-value-change-rzf3n4?file=/src/App.jsWhat is the expected behavior?
Changing the value should re-render my component
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: