React Bug Hunt Easy +10 XP
State Mutation
The UI doesn't update when the array changes.
ReactFind the bug
1
const [items, setItems] = useState([]);2
const addItem = (item) => { items.push(item); }; The bug is on line 2
Select the correct fix
Show answer and explanation
Answer: Both A and B work
React requires state updates via the setter. Direct mutation (push) doesn't trigger re-render. Create a new array instead.
Hint: React doesn't detect direct array mutations.
What this challenge tests
Bug Hunt in React: state, mutation.