Code RoomState mutation in setState
MediumPrep Room Coding #1815

State mutation in setState

Code reviewAlgorithms & data structuresMid–Senior~18 min

Review this React TypeScript component.

What a strong answer looks like

Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix, specific and kind.

0:00 of about 18 min
Mark a line and say what kind of problem it is.0 findings
1function Cart() {
2 const [items, setItems] = useState<Item[]>([]);
3 
4 const addItem = (item: Item) => {
5 items.push(item);
6 setItems(items);
7 };
8 
9 return <button onClick={() => addItem(newItem())}>Add ({items.length})</button>;
10}
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.