-
Notifications
You must be signed in to change notification settings - Fork 47.6k
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
Bug: useReducer, reducer function gets called twice (possible memory leak) #21416
Comments
Thanks for the report. If I click 2 more times it goes to 6 after increasing the limit. If I click 3 more times it goes to 7 after increasing the limit. But in your repro you say it should increase to 7. Did you either mean "it increases to 6" or "click three more times"? I forked your repro into a codesandbox and simplified it to a primitive state so that we don't get distracted: https://codesandbox.io/s/react-17-reducer-prop-closure-548bh |
You're welcome! You're right, the first time when you set the limit to a greater number, the counter will go up the number of times you've incremented the counter minus one. |
My current workaround around this is returning a new state by spreading the old state, instead of returning the old state.
Obviously, this approach will cause unnecessary reRenders. |
same as #17953 |
i would like to work on this issue |
React version: 17.0.2
Steps To Reproduce
dispatch({type:'INCREMENT'})
a few times after the counter has reached the top limitLink to code example: CODE PEN
The current behavior
After setting the top limit to a higher limit, the previous
INCREMENT
actions which are called before and the reducer have returned the intact state, will be called again and the reducer function will be called as much as you've tried before and the counter will increase that much.The expected behavior
After setting the top limit to a higher limit, the previous
INCREMENT
actions which are called before, must not be called again and the Reducer function must not be called again and the counter must stay the same.The text was updated successfully, but these errors were encountered: