Closed
Description
React version: 17.0.2
Steps To Reproduce
- Create a counter reducer with a top limit (top limit is set externally using a prop or state)
- Return the current state if the count reaches the top limit
- Try to increment the counter by calling
dispatch({type:'INCREMENT'})
a few times after the counter has reached the top limit - Set the top limit to a greater number
- You'll see that after increasing the top limit, the reducer callback will be called as much as you'd tried to increment the counter in step 3 and the counter will increment that much
Link 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.