Challenge 3: fix infinite useEffect loop #244
Merged
+11
−15
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
At some point we changed logic a bit, and
rolls
andwinners
lengths could be from 0 to 10 because all the data was sliced before updating the state. Reason for this is that we show just last 10 rolls/winnersuseEffect
s we have a condition like(rollsHistoryData?.length as number) > rolls.length)
so whenrollsHistoryData.length
becomes more than 10,rolls.length
is not - it's still 10, and it means that mentioned condition is alwaystrue
. So we havesetRolls(...)
inside thatuseEffect
-> it changesrolls
-> it executes thatuseEffect
again etc -> infinite loop. Same for winnersThis PR fixes it. Please check and after merging this I'll add changes to extension
Fixes #242