Whenever you're ready, walk me through how you'd approach this.
Anduril's operations dashboard renders a live list of sensor tracks (radar and camera detections) that updates several times a second. Operators have reported the list stuttering and occasionally showing the wrong track highlighted after clicking one. Here is the component a frontend engineer wrote.
function TrackList({ tracks, onSelect }: { tracks: Track[]; onSelect: (id: string) => void }) {
const [filter, setFilter] = useState('');
const visibleTracks = tracks
.sort((a, b) => b.threatScore - a.threatScore)
.filter(t => t.classification.includes(filter));
return (
<div>
<input value={filter} onChange={e => setFilter(e.target.value)} />
{visibleTracks.map((track, index) => (
<div key={index} onClick={() => onSelect(track.id)}>
<TrackRow track={track} onSelect={() => onSelect(track.id)} />
</div>
))}
</div>
);
}
function TrackRow({ track, onSelect }: { track: Track; onSelect: () => void }) {
console.log('rendering row for', track.id);
return <div>{track.classification} - {track.threatScore}</div>;
}
Refactor this snippet to improve its performance and readability. Explain each problem you found and what you would change, rather than submitting a new file.