Code RoomLayer visibility mutated in map
HardPrep Room Coding #2026

Layer visibility mutated in map

Code reviewAlgorithms & data structuresSenior–Staff~22 min

Review this React TypeScript toggle-in-list updater.

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 22 min
Mark a line and say what kind of problem it is.0 findings
1function Layers({ initial }: { initial: Layer[] }) {
2 const [layers, setLayers] = useState(initial);
3 
4 const toggle = (id: string) => {
5 setLayers(layers.map((l) => {
6 if (l.id === id) l.visible = !l.visible;
7 return l;
8 }));
9 };
10 
11 return <Panel layers={layers} onToggle={toggle} />;
12}
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.