mirror of
https://github.com/reactjs/react.dev.git
synced 2026-02-21 19:31:57 +00:00
Fix incorrect condition in "Chains of computations" example (#8109)
Fixes #8097 The refactored example in the "Chains of computations" section uses an incorrect condition that changes the game logic from the original. The original Effect-based code advances the round after 4 gold cards: - Increments first (0→1, 1→2, 2→3, 3→4) - Then checks `goldCardCount > 3` (true when count is 4) The refactored code with `goldCardCount <= 3` allows 5 gold cards: - Checks before incrementing - Allows counts 0, 1, 2, 3 to increment (4 values) - Advances on the 5th card (when count is 4) This fix changes the condition to `goldCardCount < 3`: - Allows counts 0, 1, 2 to increment (3 values) - Advances on the 4th card (when count is 3) - Matches the original behavior Verified by tracing execution logic and building the docs site locally. Co-authored-by: PaulyBearCoding <PaulyBearCoding@users.noreply.github.com>
This commit is contained in:
@@ -437,7 +437,7 @@ function Game() {
|
||||
// ✅ Calculate all the next state in the event handler
|
||||
setCard(nextCard);
|
||||
if (nextCard.gold) {
|
||||
if (goldCardCount <= 3) {
|
||||
if (goldCardCount < 3) {
|
||||
setGoldCardCount(goldCardCount + 1);
|
||||
} else {
|
||||
setGoldCardCount(0);
|
||||
|
||||
Reference in New Issue
Block a user