-
Notifications
You must be signed in to change notification settings - Fork 1.7k
task is ready #1754
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
base: master
Are you sure you want to change the base?
task is ready #1754
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Summary
I’m requesting changes because the Increase button behavior does not meet the core requirement and will produce an incorrect sequence. In src/App.jsx, the increase handler checks count % 5 === 0 and calls add100() before addOne() (see around the increase function), which uses the stale count value and reverses the required order. The requirement states: the Increase button must first call addOne, then, based on the updated count, additionally call add100 if the new value is divisible by 5. Because React state updates are asynchronous, checking count before calling addOne() will never reflect the incremented value.
What to fix (critical):
- Update
increaseso the divisibility check is based on the post-increment value. Hint: use a single functionalsetCountthat computesnext = prev + 1and then applies+100ifnext % 5 === 0; or ensure you derive the updated value before deciding to applyadd100.
Minor: Code style and other functions look good; addOne and add100 correctly use functional updates. Once you adjust increase as above, the sequence should follow 101, 102, 103, 104, 105, 206, etc. Nice work overall—this is a small but important logic correction.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Important
Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.
Tip
If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.
Caution
Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.
Footnotes
|
|
||
| export const App = () => { | ||
| const [count] = useState(0); | ||
| const [count, setCount] = useState(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This violates the requirement: "The 'Increase' button must first call addOne, then, if the resulting count is divisible by 5, additionally call add100." The current increase implementation checks count % 5 === 0 and calls add100() before calling addOne(), so the conditional uses the stale value of count and the order is reversed. Because React state updates are asynchronous, calling addOne() after checking count will not make the conditional observe the incremented value. Consider changing the approach so the conditional uses the incremented value — e.g. use a single functional updater like:
setCount(prev => {
const next = prev + 1;
return next % 5 === 0 ? next + 100 : next;
});This will produce the required sequence (101, 102, 103, 104, 105, 206, ...).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Summary
I’m requesting changes because the Increase button logic does not meet the core requirement and will produce incorrect behavior. In src/App.jsx, your handler calls addOne() and then checks if (count % 5 === 0) { add100(); }, which uses stale count due to React’s asynchronous state updates (see around the Increase button’s onClick handler). The requirement states: Increase must first add 1 and then, based on the updated value, add 100 if the new value is divisible by 5; the current implementation won’t yield the expected sequence (e.g., 101, 102, 103, 104, 105, 206, …).
What to fix (critical):
- Update the Increase handler to base the divisibility check on the post-increment value using a single functional state update. Hint: compute
next = prev + 1insidesetCount(prev => ...)and then returnnext % 5 === 0 ? next + 100 : next.
Positives: addOne and add100 correctly use functional updates and the UI renders as expected. Once you adjust the Increase handler as above, the behavior should align with the requirements and likely pass related tests. Keep going—you’re very close.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Important
Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.
Tip
If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.
Caution
Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.
Footnotes
src/App.jsx
Outdated
| addOne(); | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This violates the requirement: "Increase button calls addOne and then, if count is divisible by 5, it additionally calls add100." The current code calls addOne() and then checks if (count % 5 === 0) { add100(); }. Because React state updates are asynchronous, count is still the old value here and the divisibility check uses stale state, so the required sequence will not be produced. Consider using a single functional update so the check is based on the post-increment value, for example:
setCount(prev => {
const next = prev + 1;
return next % 5 === 0 ? next + 100 : next;
});This guarantees the check uses the updated count and will produce the expected sequence (101, 102, 103, 104, 105, 206, ...).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Summary
I am approving this submission as an educational override to help you progress while learning. Great job implementing addOne, add100, and wiring the buttons; your state setup looks solid. However, there’s a critical issue in src/App.jsx: in the increase handler (around the block where you call addOne() and then setCount(c => { ... })), the divisibility check uses the pre-increment value c, and that setCount returns c unchanged, which breaks the required behavior (the spec says: increase by 1, then if the new value is divisible by 5, add 100). To fix it, compute the next value in a single functional update and check divisibility on the post-increment value, e.g., set next = prev + 1 and return next % 5 === 0 ? next + 100 : next. This approach avoids stale state and ensures the correct sequence (101, 102, 103, 104, 105, 206, ...). Minor: remove the extra setCount that returns the old value to keep the logic clear. Nice work overall—tighten the increase logic and you’ll be fully aligned with the requirement.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Footnotes
src/App.jsx
Outdated
| setCount(c => { | ||
| if (c % 5 === 0) { | ||
| add100(); | ||
| } | ||
|
|
||
| return c; | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This violates the task description requirement: "Increase button calls addOne and then, if count is divisible by 5, it additionally calls add100."
Current problems in this block:
- The code calls
addOne()and then runs asetCount(c => { ... })that checksif (c % 5 === 0) { add100(); }and returnsc. That check uses the pre-increment valuec, not the value after +1, and the function returns the oldc(so this secondsetCountdoesn't advance the count). This reliance on stale state breaks the required behavior and sequence.
Suggestion: replace the whole increase logic with a single functional update so the new value is computed and inspected inside one setCount call. For example:
setCount(prev => {
const next = prev + 1;
return next % 5 === 0 ? next + 100 : next;
});This ensures the divisibility check is performed on the post-increment value and avoids asynchronous/stale-state bugs. (Keep addOne and add100 as separate functions for the other buttons.) Reference: current file src/App.jsx where the faulty block is implemented.
No description provided.