Symptom
When clicking "Add Set", the parent's onSetsChange callback receives an array that's always one set behind. The first click reports 0 sets, the second click reports 1 set, etc.
Expected
After clicking "Add Set", the parent should immediately receive the updated array including the new set.
What you know
This is a React component that manages a list of workout sets. When the user clicks "Add Set", the component should:
- Add a new set to its internal state
- Notify the parent of the updated set list via
onSetsChange
The bug is in handleAddSet — the parent always receives a stale array.
Hints
TypeScript
TypeScript ready
Test Output
▶
Click "Run Tests" to execute your code